Bookmark Topic Watch Topic
  • New Topic

Waiting for all threads to die  RSS feed

 
Krishna Attravanam
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi

How do I ensure all threads finish executing before main() continues. I used something like this:


for (int i : NUM_THREADS) {
threads.start();
}

for (int i : NUM_THREADS) {
threads.join(); // line 1
}

Does join() queue up the execution of threads ? For example, if threads 1 and 2 are running, main will wait at line 1 for thread 1 to die before going to the start of "for" loop. This will effectively rule out the concurrent execution model of the thread. Is there any other way of doing this? Or am I misinterpreting this?

Let me know
Thanks
M
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66304
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please do not cross-post the same question in multiple forums. It wastes people's time when multiple redundant conversations take place.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!