• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to make parent thread wait for child thread to complete  RSS feed

 
yogesh seth
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
From my main thread, i am spawning few child threads.



In the last method call, i want to do something which requires all the threads to be finished processing. One brute force approach is to implement the method waitForAllThreadsAndDoSomething() in the following manner:


but this is too ugly and memory consuming.

can anyone suggest a cleaner approach by using methods in thread class like: wait(), notify(), yeild() ?

cheers
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look into join(). You'd do something like

See if that does it for you!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!