Win a copy of Learning Java by Building Android Games this week in the Android forum!
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Waiting for all threads to die  RSS feed

Posts: 3
  • Mark post as helpful
  • send pies
  • Report post to moderator

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

for (int i : NUM_THREADS) {

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
Author and ninkuma
Posts: 66820
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!