• Post Reply 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

join() in threads

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
I am confused with the below code which is from khalid Mughal's book


Output on my machine: 23 24 21 13 14 11 22 12
Main Thread prints 23 at line 1
Thread-0 is started.
Main Thread prints 24 at line 2
Thread-0 prints 21 at line 3
t1.join at line 4 makes Thread-0 to join after the Main thread is complete.
So Main thread continues and returns t2.
Again 13 is printed at line 1
Thread-1 is started
14 is printed at line 2
11 is printed at line 3
I don't understand how 22 is printed. Can anyone explain it?

Thanks
Sravani
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This piece of code has been thoroughly discussed here. Let us know if that answers your question.
 
sravani jetty
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Marc,
Thanks a lot for the link. It cleared my doubt.

Thanks
Sravani
 
reply
    Bookmark Topic Watch Topic
  • New Topic