This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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.


  •  
    wood burning stoves
     
    subject: Thread join()
     
    Similar Threads
    wait() releases all locks?
    Question ID :988384705515 JQ+
    Threads
    THread Selection By JVM Problem
    Object pass by value