aspose file tools*
The moose likes Threads and Synchronization and the fly likes wait+ interruptedException 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 » Threads and Synchronization
Bookmark "wait+ interruptedException" Watch "wait+ interruptedException" New topic
Author

wait+ interruptedException

kumarth ravi
Ranch Hand

Joined: Jun 01, 2007
Posts: 48
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

Joined: Jul 08, 2003
Posts: 24168
    
  30

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.


[Jess in Action][AskingGoodQuestions]
Nicholas Jordan
Ranch Hand

Joined: Sep 17, 2006
Posts: 1282
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()
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: wait+ interruptedException
 
Similar Threads
Synchornized Block..
Doubt in synchronized thread program
Synchronizing between two threads, one implements Runnable the other extends Thread
join() method in Thread doesn't work as expected
help regarding synchronized methods