I think that the "call thread" the author had in mind some kind of callback from the workflow to the main thread to notify him of some event.
There are many ways to implement such a callback, but I would use a simple listener interface. Something like that:
//Interface of the listener that listens to image load events public interface ImageLoadListener { void onImageLoadSuccess(ImageInformation image); void onImageLoadFailed(ImageInformation image); } //Worker thread that loads images and notifies the listener about success public class ImageLoader implements Runnable { private final ImageLoadListener loadListener; public ImageLoader(ImageLoadListener listener) { this.loadListener = listener; } public void run() { .... for (each image to load) { .... if (load(image)) { if (loadListener != null) { loadListener.onImageLoadSuccess(image); } } else { if (loadListener != null) { loadListener.onImageLoadFailed(image); } } } } } //Main class that creates working threads and processes loaded images public class MainClass { ... //Main method for processing loaded image void showImageAfterLoad(ImageInformation information) { ... } //Some button that should create the worker thread void onSomeButtonClick() { //Instantiate the listener interface. If image load is successful - run showImageAfterLoad function on MainClass ImageLoadListener listener = new ImageLoadListener() { void onImageLoadSuccess(ImageInformation image) { MainClass.this.showImageAfterLoad(image); } void onImageLoadFailed(ImageInformation image) { //Do nothing } }; //Create loader and it thread ImageLoader loader = new ImageLoader(listener); new Thread(loader).start(); } }
If you need it to be scalable, I would recommend changing it to some implementation of the Bus Bus template. For example: http://code.google.com/p/simpleeventbus/
The event bus is usually the same as I wrote in my example, but it is very scalable. The main difference is that you can manage different types of events and register many listeners at once.
bezmax
source share