This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "API for wait question" Watch "API for wait question" New topic
Author

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
author
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: API for wait question
 
Similar Threads
threads
Thread Question
Can notify() be called on a thread that has not started yet?
Problem in Threading - 2
Clarification in wait, notify and notifyAll methods