• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

wait+ interruptedException

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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()
 
Not so fast naughty spawn! I want you to know about
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic