Search code examples
javaswingworker

How to make SwingWorker wait for threads started from within this SwingWorker


I have problem with SwingWorker and it's done() method. I have an application that supports plugins through SPI, so I basically can't change the behavior of the plugins. The interface these plugins have to implement contains method List<T> getContracts(). This is the method I am calling from SwingWorker's doInBackground() method. But some of the plugins use multiple threads in this getContracts() method. The problem is, that the done() method is then called before these threads finish. Is there a way to make SwingWorker thread not to finish (not to call it's done() method) until all the threads called from this SwingWorker stop?

Thanks for your help.


Solution

  • It seems you should just be wrapping this question in your SwingWorker done() method.