Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads and Exceptions

 
Surendra Kumar
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am confused with thread exceptions.
can someone please explain the difference in the exceptions InterruptedException, IllegalMonitorStateException, IllegalThreadStateException.

which exception th wait() method should be wrapped in?
 
Ramamoorthy Periasamy
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
InterruptedException
 
Vepa Sritej
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
InterruptedException is thrown when any thread is interrupted while it has executed sleep() or wait().
IllegalMonitorState Exception is thrown when any thread executes wait() without holding a lock on an object.

InterruptedException must be handled via try..catch or must be declared in the method defintion. IllegalMonitorState is thrown by JVM..
 
Surendra Kumar
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what about IllegalThreadStateException?
 
Praveen Babu
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When the start() method is called twice on single thread then it throws IllegalThreadStateException.

Regards,
Praveen
http://www.javahub.co.nr
http://praveen.awardspace.com
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic