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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值