0

I'm wondering if there is a way to check in Swingworker (possibly in doBackground),if all threads are done.

I have an event I would like to execute but at the moment it executes at the end of each thread rather than when all threads are done.

Is there a way of checking if there are no more threads to execute so I can execute my second event?

Thanks

cryptiblinux
  • 29
  • 3
  • 12
  • you should overide done method in swingworker – Piotr Rogowski Mar 10 '17 at 11:53
  • Do you know how many are started? In that case, using `done` in conjunction with a CountdownLatch may be for you? Or even a simple shared counter that will start the second Event as soon as counter reaches 0 in `done`. – Fildor Mar 10 '17 at 12:00
  • @Abihabi87 Does done() check when one thread is done, or all of them? – cryptiblinux Mar 10 '17 at 12:01
  • @Fildor It can vary – cryptiblinux Mar 10 '17 at 12:02
  • So you don't start all of them at once. There could be 3 running already and then a 4th is started? Or is it more like you start sometimes 3 at once and want to wait for those 3 some other time you start 5 ... – Fildor Mar 10 '17 at 12:06
  • @Fildor's is correct, an example using `CountDownLatch` is shown [here](http://stackoverflow.com/a/11372932/230513). If this is not a duplicate, please edit your question to include a [mcve] that shows your revised approach. – trashgod Mar 10 '17 at 12:17

0 Answers0