E
E. Naubauer
Hello everybody, I want to do the following:
I have an application that continuously receives and decodes images from
a stream. Since image decoding is an expensive task, I decided to
create a new thread that listens for incoming fragments and decodes them.
Basically my program has 2 classes:
class MainDialog extends Frame
{
Image currentImage;
public void receiveImages(...)
{
<this Method receives images from the decoding thread and
updates current image>
}
}
class ImageDecodingThread implements Runnable
{
public void run()
{
while(true)
{
//get next image from stream
//notify all Objects that are interested
in the current image and make them update their
local copies. Then they should redraw their window
content with the image
}
}
}
My question is what is the best way to do communication between the
ImageDecodingThread and the MainDialog object? I thought about
implementing the ChangeListener Interface in MainDialog and dispatching
ChangeEvent events from the ImageDecoding-Thread if a new image
arrives. However, using the standard EventListenerList model that
goes through the list of listening objects calling each objects
stateChanged Method is something I have only implemented between
objects used within the same thread. So does anyone know a good
standard approach to have one thread doing the whole gui and drawing
stuff and the other one receiving events and passing them to the
gui thread (especially typical synchronization issues)?
Thanks for any advice
I have an application that continuously receives and decodes images from
a stream. Since image decoding is an expensive task, I decided to
create a new thread that listens for incoming fragments and decodes them.
Basically my program has 2 classes:
class MainDialog extends Frame
{
Image currentImage;
public void receiveImages(...)
{
<this Method receives images from the decoding thread and
updates current image>
}
}
class ImageDecodingThread implements Runnable
{
public void run()
{
while(true)
{
//get next image from stream
//notify all Objects that are interested
in the current image and make them update their
local copies. Then they should redraw their window
content with the image
}
}
}
My question is what is the best way to do communication between the
ImageDecodingThread and the MainDialog object? I thought about
implementing the ChangeListener Interface in MainDialog and dispatching
ChangeEvent events from the ImageDecoding-Thread if a new image
arrives. However, using the standard EventListenerList model that
goes through the list of listening objects calling each objects
stateChanged Method is something I have only implemented between
objects used within the same thread. So does anyone know a good
standard approach to have one thread doing the whole gui and drawing
stuff and the other one receiving events and passing them to the
gui thread (especially typical synchronization issues)?
Thanks for any advice