Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

wait and notify are said to be communication mechanism in threads but then why are they not declared in Thread class and are declared in Object class instead?

share|improve this question
    
Stack Overflow search shows 169 results: stackoverflow.com/search?q=Why+notify+and+wait+are+in+object I't also FAQ'd at Code Ranch: Why are wait(), notify(), and notifyAll() in the Object class? –  gnat Jan 9 '13 at 11:07

1 Answer 1

because each object is a monitor

and so you can have multiple sets of waiting threads, and having to manage waiting threads yourself requires extra bookkeeping (now handled by the VM) and is prone to deadlock and other thread related bugs

share|improve this answer
    
no because the implementers of the JVM are smart enough to avoid them –  ratchet freak Jan 9 '13 at 11:11
    
Many thanks for the answer and also for the links posted! –  Anjani Jan 9 '13 at 11:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.