File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Threads and Synchronization and the fly likes API for wait question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "API for wait question" Watch "API for wait question" New topic

API for wait question

Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
If a thread becames "notified" then API states

The thread T is then removed from the wait set for this object and re-enabled for thread scheduling. It then competes in the usual manner with other threads for the right to synchronize on the object; once it has gained control of the object, all its synchronization claims on the object are restored to the status quo ante - that is, to the situation as of the time that the wait method was invoked. Thread T then returns from the invocation of the wait method. Thus, on return from the wait method, the synchronization state of the object and of thread T is exactly as it was when the wait method was invoked.

Is there any possibilty that the synchonization state of the object is not "synchronized" before the call to wait?
The API doesn't explicity say that the monitor was adquired before calling wait. Any particular reason?

SCJP2. Please Indent your code using UBB Code
Peter den Haan
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
No, that's not possible. Object.wait() throws an IllegalMonitorStateException if you don't have a monitor lock on the object. See the Javadoc.
- Peter
I agree. Here's the link:
subject: API for wait question
It's not a secret anymore!