aspose file tools*
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
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: 18990
    
  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