This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Do JVM notifies on waiting threads?  RSS feed

 
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please do consider the following Program

Query : Main thread is waiting for Object t which unfortunately can not notify because it is already not-alive. But inspite of this fact, i am getting ouput X,
which conveys me that JVM notifies iff thread waits on certain object which is already dead. Is this conclusion true or i am misleading somewhere??

Please help !!!

 
author
Sheriff
Posts: 23571
138
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What you are seeing is an implementation detail -- specifically, the implementation detail of the join() method. The join() method uses a combination of checking if the thread is alive and calling the wait() method. And it calls the wait() method of the Thread object. When a thread terminates, part of the cleanup process is to call the notifyAll() method, after the thread has been set to no longer alive.

Since you are just using a Thread object, with no runnable, it will just quickly terminate. And the cleanup process will send the notification that is waking up your main thread.

Henry
 
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Henry, it's a good response! And Sahil have look on this regarding join() method.
 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry , but not getting it clearly...

If suppose Thread A is waiting on Object O and O never calls notify or notifyALL......Then i conclude that Thread A would never be Runnable and consequently running...

Is this true ???

If it is ....What is cleanup process is all about ???

 
Henry Wong
author
Sheriff
Posts: 23571
138
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Sahil Kapoor wrote:Sorry , but not getting it clearly...

If suppose Thread A is waiting on Object O and O never calls notify or notifyALL......Then i conclude that Thread A would never be Runnable and consequently running...

Is this true ???

If it is ....What is cleanup process is all about ???



It's simple. There are TWO things going on that is using the Thread object for notification. Your stuff, and the built in libraries, which is using it to do implement join(). And you two are stepping on each other.

My previous post was explaining the other thing -- not what your code is doing.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!