Java - SwingWorker - problem

Posted by Yatendra Goel on Stack Overflow See other posts from Stack Overflow or by Yatendra Goel
Published on 2010-05-08T06:03:58Z Indexed on 2010/05/08 6:08 UTC
Read the original article Hit count: 328

Filed under:
|
|
|

I am developing a Java Desktop Application. This app executes the same task public class MyTask implements Callable<MyObject> { in multiple thread simultaneously.

Now, when a user clicks on a "start" button, I have created a SwingWorker myWorker and have executed it.

Now, this myWorker creates multiple instances of MyTask and submits them to an ExecutorService.

Each MyTask instance has a loop and generates an intermediate result at every iteration. Now, I want to collect these intermediate results from each MyTask instances as soon as they are generated. Then after collecting these intermediate results from every MyTask instance, I want to publish it through SwingWorker.publish(MyObject) so that the progress is shown on the EDT.

Q1. How can I implement this? Should I make MyTask subclass of SwingWorker instead of Callable to get intermediate results also, because I think that Callable only returns final result.

Q2. If the answer of Q1. is yes, then can you give me a small example to show how can I get those intermediate results and aggregate them and then publish them from main SwingWorker?

Q3. If I can't use SwingWorker in this situation, then how can I implement this?

© Stack Overflow or respective owner

Related posts about java

Related posts about swingworker