Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help with Thread Sleep  RSS feed

 
bob morkos
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Henry Wong
author
Sheriff
Posts: 23275
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


I agree. This is like scratching your right ear with your left hand. It's possible but why? And BTW:

sleep(new Long(50).longValue());

is also equivalent in effect to

sleep(50L);

Henry
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try reading the javadoc for the wait method. I always download the API docs with the JDK since they are so valuable in knowing what the methods do.



This program wont work though. That is one reason i recommend NEVER using synchronized methods.

try instead


it still needs work, but ill leave that to you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!