Labels
- Apache (10)
- Articles (4)
- BPM Tools (5)
- Glassfish (16)
- Hadoop (10)
- HP ALM (6)
- HP SOA Systinet (14)
- Issues (19)
- JAVA (85)
- JBoss (16)
- jQuery (4)
- Load Runner (37)
- Quality Center (49)
- Testing (24)
- Tips and Tricks (16)
- Tomcat (4)
- Usefull Links (18)
- Weblogic (41)
- WebSphere (2)
Monday, June 11, 2012
Why are wait(), notify(), and notifyAll() in the Object class in java?
After all, these methods have something to do with threads, so why aren't they in the thread class?The answer is that Threads can use Objects to transmit messages from one thread to another, and these methods allow that to happen. A Thread calls wait() to say "I am waiting for a message to be sent to this object." Another thread can call notify() to say "Iam sending a message to that object." The Object is therefore a conduit through which threads communicate without explicitly referencing each other. If the methods were in theThread class, then two threads would need to have references to one another to communicate. Instead, all communicating threads just need to agree to use some specific shared resource
Labels:
JAVA
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment