• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Interactions of Waits, Notification and Interruption (JLS)

 
Ranch Hand
Posts: 664
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The above specifications allow us to determine several properties having to do with the interaction of waits, notification and interruption. If a thread is both notified and interrupted while waiting, it may either:
return normally from wait, while still having a pending interrupt (in other works, a call to Thread.interrupted would return true)
return from wait by throwing an InterruptedException
The thread may not reset its interrupt status and return normally from the call to wait.
Similarly, notifications cannot be lost due to interrupts. Assume that a set s of threads is in the wait set of an object m, and another thread performs a notify on m. Then either

at least one thread in s must return normally from wait, or
all of the threads in s must exit wait by throwing InterruptedException
Note that if a thread is both interrupted and woken via notify, and that thread returns from wait by throwing an InterruptedException, then some other thread in the wait set must be notified.

Source Java Language Specification (3rd Edition), available here.

What is the difference between notified, and, interrupted from a technical point of view?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jon Camilleri wrote:
What is the difference between notified, and, interrupted from a technical point of view?



They are simply two different mechanisms, and have very distinctive purposes. It would be a good idea to learn both mechanisms first, before trying to figure out how the JLS defines how they interact.

BTW, it would also be a very good idea to learn and get comfortable with threads and synchronization prior to both of these mechanisms too.

Henry
 
Jon Camilleri
Ranch Hand
Posts: 664
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:

Jon Camilleri wrote:
What is the difference between notified, and, interrupted from a technical point of view?



They are simply two different mechanisms, and have very distinctive purposes. It would be a good idea to learn both mechanisms first, before trying to figure out how the JLS defines how they interact.

BTW, it would also be a very good idea to learn and get comfortable with threads and synchronization prior to both of these mechanisms too.

Henry



What's a good place to start?
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jon Camilleri wrote:
What's a good place to start?



I guess it depends on where you are. If you aren't comfortable with threads, perhaps you should start to learn threads. If you are somewhat comfortable, but don't know synchronization, then maybe that is a place to start. Definitely get comfortable with threads and synchronization first.

Henry
 
Jon Camilleri
Ranch Hand
Posts: 664
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:

Jon Camilleri wrote:
What's a good place to start?



I guess it depends on where you are. If you aren't comfortable with threads, perhaps you should start to learn threads. If you are somewhat comfortable, but don't know synchronization, then maybe that is a place to start. Definitely get comfortable with threads and synchronization first.

Henry



Any recommended reading, apart from my current read, Core Java Volume I (8th Ed.)?
reply
    Bookmark Topic Watch Topic
  • New Topic