This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hi, I tried an example for wait() after reading a tutorial.
The Example is as below:
On executing theabove I get the below error.
Exception in thread "main" java.lang.IllegalMonitorStateException: current thread not owner at java.lang.Object.wait(Native Method) at java.lang.Object.wait(Object.java:474) at com.aciworldwide.application.TestApp.main(TestApp.java:19)
Where am I doing wrong.What does the error mean how can I correct it?
* Thread should obtain the object's monitor before invoking wait() or notify() on it. * Locks,synchronized blocks/methods are the techniques to acquire object monitor. Depending on application requirement,suitable technique should be adopted. * wait() should always be matched with a notify(). If you get rid of java.lang.IllegalMonitorStateException in the above example by aquiring the object's(one) monitor,main-thread will wait for-ever. * You may find this discussion helpful. [ June 05, 2008: Message edited by: sarvesh meens ]