Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Interactions of Waits, Notification and Interruption (JLS)  RSS feed

 
Jon Camilleri
Ranch Hand
Posts: 664
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • 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?
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • 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.)?
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!