aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread 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 "Thread join()" Watch "Thread join()" New topic
Author

Thread join()

Sam Samson
Ranch Hand

Joined: Oct 08, 2011
Posts: 61

Hi

An example from SCJP-Book:



Is it right that the output could be "r1 m1 r2 m2"? I'm asking because this answer is missing in the possible solutions.


greez
Sam
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Sam Samson wrote:
Is it right that the output could be "r1 m1 r2 m2"? I'm asking because this answer is missing in the possible solutions.


Yes, that output is possible.

The constraints are as follows:

  • m1 will come before m2, since they're in the same thread and that's the order they're in in the code.
  • Similarly, r1 will come before r2, for the same reason.
  • Everything in the new thread will happen before m2, since that's after the join().


  • Any order that adheres to those constraints is valid. And we can actually simplify it down to:
  • r1 will come before r2.
  • m2 will be last.


  •  
    Consider Paul's rocket mass heater.
     
    subject: Thread join()