This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Threads and Synchronization and the fly likes The wai() method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "The wai() method" Watch "The wai() method" New topic
Author

The wai() method

ravinderSingh singh
Ranch Hand

Joined: Nov 18, 2004
Posts: 41
When a thread invokes the wait() method on an object whose lock it holds, does the thread only release the lock on the object it invoked the wait method on, or does it release all the object locks it holds (assuming it holds other object locks)?

Thanks
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18754
    
  40

Both...

The wait() method will only release the lock of the object that you are waiting on. However, it is possible to grab the same lock more than once, and the wait method will release *all* the grabs of the waiting lock.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The wai() method