Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!
    Bookmark Topic Watch Topic
  • New Topic

Waiting for all threads to die  RSS feed

 
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
 
Author and ninkuma
Marshal
Posts: 66729
167
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.
 
A teeny tiny vulgar attempt to get you to buy our stuff
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!