Reputation: 779
I have the following task:
I need to do every step into another thread. It seems, that when I'm done with loading image I need to transfer it into second thread.
After some googling I realized that I need to implement Callable interface to each thread and than use it with ExecutorService. The problem is that I don't understant how to pass data, for example, from first thread to second.
Can anyone show a simple example of it? thanks
Upvotes: 0
Views: 167
Reputation: 583
You can use java.util.concurrent.Exchanger. This is synchronization point at which two threads can exchange objects. For more details see http://docs.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/Exchanger.html
Upvotes: 0
Reputation: 15709
Use BlockingQueue and a Producer-Consumer pattern.
In this approach, the first thread will download your images and put them inside the queue. The second thread will wait until something appears inside the queue, transform the image, and put it in another queue, that the third thread will wait for.
Read the articles I've linked to for more explanation and a working example of the Producer-Consumer pattern.
Upvotes: 5