This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Java in General and the fly likes Need help with Thread Sleep Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Need help with Thread Sleep" Watch "Need help with Thread Sleep" New topic
Author

Need help with Thread Sleep

bob morkos
Ranch Hand

Joined: Oct 06, 2003
Posts: 56
I get the following error, could anyone help?

[error]
java.lang.IllegalMonitorStateException: current thread not owner at java.lang.Object.wait(Native Method) at java.lang.Object.wait(Object.java:420)
[/error]

Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24168
    
  30

In the method retrieveTransponderResult, you call wait() on the daoThread object, but you're not in a synchronized method of Thread, nor in a block synchronized on that Thread object. To call wait() or notify(), you have to hold the monitor of the object you're calling them on. This is explained in the Javadoc for those methods.

I can't resist pointing out that

return new Boolean("false").booleanValue();

is exactly equivalent in effect to

return false;

except, of course, that it's vastly more expensive computationally.

This is not an advanced Java question, but a beginner's Thread question; I'm moving this to the Threads forum.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help with Thread Sleep
 
Similar Threads
Need help with Thread Sleep
How to set a time limit on a java function running a regex
Feed the Pets
Timer use?
Rotating Squares in java