permaculture playing cards*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes confusion in join() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "confusion in join()" Watch "confusion in join()" New topic
Author

confusion in join()

Rituparna Duttagupta
Ranch Hand

Joined: Feb 08, 2011
Posts: 55

hi everyone!
please help me to get the join() method correctly.
say, i have 2 threads- t1 and t2. now, if i call t1.join(); inside t2's run() method, then is it that t1 will join after t2? Or t2 will join after t1 completes?


With regards,
rituparna
Rajasekar Krishnan
Greenhorn

Joined: Feb 27, 2008
Posts: 16

Hi Rituparna,



Result:

2T0
2T1
2T2
2T3
2T4
2T5
2T6
2T7
2T8
2T9
2T10
1T0
1T1
1T2
1T3
1T4
1T5
1T6
1T7
1T8
1T9
1T10


When you do join on T2, T1 waits till the T2 to complete its execution, and then T1 continues.


Thanks,
Rajasekar.
Rajasekar Krishnan
Greenhorn

Joined: Feb 27, 2008
Posts: 16

Hi Rituparna,



Result:

2T0
2T1
2T2
2T3
2T4
2T5
2T6
2T7
2T8
2T9
2T10
1T0
1T1
1T2
1T3
1T4
1T5
1T6
1T7
1T8
1T9
1T10


When you do join on T2 in T1 Run method, T1 waits till the T2 to complete its execution, and then T1 continues.


Thanks,
Rajasekar.
Rituparna Duttagupta
Ranch Hand

Joined: Feb 08, 2011
Posts: 55

thanks Rajasekar, now i think i got it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: confusion in join()