06-Condition
Condition的API
public interface Condition {
/**
* 让当前线程进入等待状态直到被通知或者被中断,当前线程重新进入运行状态且从await方法返回的情况如下
* 1. 其他线程调用了该Condition的signal 或signalAll
* 2. 其他线程调用interrupt中断了当前线程
* @throws InterruptedException
*/
void await() throws InterruptedException;
/**
* 等价上面那个
* @param time
* @param unit
* @return
* @throws InterruptedException
*/
boolean await(long time, TimeUnit unit) throws InterruptedException;
/**
* 指定到某个时间还没被通知且没被中断直接返回,提前被通知了返回true,否则false
* @param deadline
* @return
* @throws InterruptedException
*/
boolean awaitUntil(Date deadline) throws InterruptedException;
/**
* 唤醒等待在Condition上的一个线程
*/
void signal();
/**
* 唤醒所有等待在Condition上的线程
*/
void signalAll();
}基本原理
等待队列
最后更新于