Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread join()

 
Sam Samson
Ranch Hand
Posts: 63
IntelliJ IDE Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


  •  
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic