• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

wait+ interruptedException

 
kumarth ravi
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you,

I will give one scenario .



My question is
---------------

Two threads
a)WaitStateThread gets lock on the shared resoucre and by executing wait it goes to waiting state.

b) ReleaseThread, it releases the thread(t1) the from the waiting queue,by executing the method.

now what is the role of InterruptedException ,in above program t1 ,t2 and
main thread is there,so who will generate the interruptedException.

Can you give clear explantion on that.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this program, there won't be any InterruptedExceptions. If another thread called t1.interrupt() during the wait() call, then you's get one.

Moving to our Threads and Synchronization forum.
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about this scenario ?


What I have done here is a narrow focus on: what is the role of InterruptedException and my re-code may not be effective for Can you give clear explantion on that. Also, it may or may not interrupt, depending on things the code does not attempt to control. As EFH states, your originally posted code does not call interrupt() - which would mean no InterruptedException to catch.

For Object.notify() we have:

/**
* The awakened thread will not be able to proceed until the current thread relinquishes the
* lock on this object. The awakened thread will compete in the usual manner with any other
* threads that might be actively competing to synchronize on this object; for example, the
* awakened thread enjoys no reliable privilege or disadvantage in being the next thread to
* lock this object.
*/

Which does not say anything about InterruptedException, the re-write uses Thread.interrupt()
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic