• Post Reply Bookmark Topic Watch Topic
  • New Topic

To know when thread stops

 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please could someone give me some design advice... I'm writing some software to send mail but I need the mail part to be on a thread. I've been battling it out but I was hoping someone might have a good idea for me.

Class A starts many threads of class B.
Class B must run independantly of class A.
I expect class A to finish execution before classes B.
Once all the class B threads are finished, I must execute class C.

How do I know when all the B's are done so that I can class C?

Thanks in advance,
Rachel
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Thread.join() method returns only when a Thread terminates, so the common way to do this is something like



The thread that is executing this loop will of course be basically suspended until all the B threads are done, and then will continue. If you can't have A pause like this, then you'll need to create yet another Thread to do the waiting.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!