Hi all,
For Reasons too Complicated to Explain, I would like to implement
a set of methods similar to Graphics.drawImage(), only without the
ImageObserver argument. These methods should block until the image
is completely drawn, i.e. I would like to implement a synchronous
variant of drawImage().
I intend to use these methods in a setting where all drawImage calls
will use Images that were constructed using MemoryImageSources, so
there should be no performance hit from disabling concurrency.
I was thinking about implementing my custom drawImage() methods as
wrappers around the corresponding Graphics.drawImage() methods; to pass
'this' as the ImageObserver, and to implement the ImageObserver
interface by writing an imageUpdate() method which would check for
'infoflags & ImageObserver.ALLBITS != 0' to determine if the image
has been completely drawn. When the image is completed, I would call
notify() on some object, and my custom drawImage() method would
wait() on that same object to decide when to return.
However, I'm concerned about the possibility that notify() would get
called before I even wait(). Will I end up blocking indefinitely in
that case?
I suppose I could achieve my goal, sort of, by just using a boolean
instance variable; clearing that just before the Graphics.drawImage()
call; setting it in my imageUpdate() method when it receives
ALLBITS; and waiting for it to get set by doing something like
'while (!ready) sleep(10)', but that looks ugly and it introduces a
possible delay which I would like to avoid.
If anyone has accomplished something like this, or if there is some
sample code on the web that would help me out, I would greatly
appreciate a pointer! (I know that I could probably get this to work
through trial and error, on my machine at home, but I am wary of
miltithreading gotchas where things would work significantly
differently on different platforms.)
Thanks in advance!
- Thomas.