`
onray
  • 浏览: 5877 次
  • 来自: ...
最近访客 更多访客>>
社区版块
存档分类
最新评论

Coordination Support in Class Object

阅读更多
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.

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics