This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread with same instance as lock Query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread with same instance as lock Query" Watch "Thread with same instance as lock Query" New topic
Author

Thread with same instance as lock Query

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634



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


OCPJP 6.0 93%
OCPJWCD 5.0 98%
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

You are correct.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread with same instance as lock Query
 
Similar Threads
PRoblem On threads
Threads using two different instances Problem
synchronized threads
synchronize method call
Concurrency Gurus, It's for you!