Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

an exception about thrad

 
Paul Sun
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I use wait(), I get the following exception
java.lang.IllegalMonitorStateException: current thread not owner
Could someone tell me the reason?
Thank you.
Paul
 
Nate Johnson
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Sun:
When I use wait(), I get the following exception
java.lang.IllegalMonitorStateException: current thread not owner
Could someone tell me the reason?

You are going to have to put it in a synchronized block or method depending on what you are waiting on... of you are just calling wait() you are really doing this.wait() and that line needs to be in a synchronized method like I said above or in a block like this...

and it will probably need to be in a try-catch to catch InteruptedExceptions.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!