Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread with same instance as lock Query

 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Is the following output possible ?

i think it is possible.
both threads lock on same instance,so they would block each other
any one either main or thread-0 thread-1 can run first
but i think jvm can stop thread 0 in between and run main and then switch back to thread-0

jusbeforesleep
Thread-0
main
Thread-0
jusbeforesleep
Thread-1
Thread-1
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are correct.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic