The Artima Developer Community
Sponsored Link

Chapter 20 of Inside the Java Virtual Machine
Thread Synchronization
by Bill Venners

<<  Page 4 of 4

Advertisement

Coordination Support in Class 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.)

Table 20-2. The wait and notify methods of class Object

On the CD-ROM

The CD-ROM contains the source code examples from this chapter in a subdirectory of the threads directory.

The Resources Page

For more information about the material presented in this chapter, visit the resources page: http://www.artima.com/insidejvm/resources.

<<  Page 4 of 4


Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use