Sponsored Link •
|
Advertisement
|
Object
Class Object
declares five methods that enable programmers to access the Java virtual machine's support for the coordination aspect of synchronization. These methods are declared public and final, so they are inherited by all classes. They can only be invoked from within a synchronized method or statement. In other words, the lock associated with an object must already be acquired before any of these methods are invoked. The methods are listed in Table 20-2.
Table 20-2. The wait and notify methods of class Object
Method | Description |
---|---|
void wait(); |
Enter a monitor's wait set until notified by another thread |
void wait(long timeout); |
Enter a monitor's wait set until notified by another thread or timeout milliseconds elapses |
void wait(long timeout, int nanos); |
Enter a monitor's wait set until notified by another thread or timeout milliseconds plus nanos nanoseconds elapses |
void notify(); |
Wake up one thread waiting in the monitor's wait set. (If no threads are waiting, do nothing.) |
void notifyAll(); |
Wake up all threads waiting in the monitor's wait set. (If no threads are waiting, do nothing.) |
Object
The CD-ROM contains the source code examples from this chapter in a subdirectory of the threads
directory.
For more information about the material presented in this chapter, visit the resources page: http://www.artima.com/insidejvm/resources
.
Sponsored Links
|