Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code 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:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Interview q

 
Ranch Hand
Posts: 8943
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are methods wait, notify,notifyall in Object class and not Thread class.
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I don't know if I understand your question correctly, but you must have an object associated with a thread and they will be in a wait state, just like when you synchronize, you synchronize on an object.
Here is an explanation for those terms maybe it will be clearer:
Wait : synchronized, will release the lock and do other process before it continues. Uses try-catch block exceptions. There is a wait method with a timeout in ms. After the time is exhausted, the Thread attempts to proceed but is allowed to do so only if no other Thread has a lock on the object. This method is handy when you are not sure that another Thread will be able to call notify, because it guarantees that the Thread will not be stuck in the wait state forever.
Notify : synchronized , when called, a Thread is removed from the wait set and returned to the list of Runnable Threads.
NotifyAll : synchronized, call if there is more than one thread waiting. This removes all waiting threads from the wait list. Only one of these actually get the lock on the object and is allowed to execute the synchonized method; the others run and find that the object is still locked.
If a thread has a lock on one or more objects dies, the JVM removes the locks and does the equivalent of notifyAll for each object locked.
 
chad stevens
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I understand what you are talking about, this article will answer your question:
http://java.ittoolbox.com/documents/document.asp?i=2185&r=default.asp
 
I will open the floodgates of his own worst nightmare! All in a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic