//常用:
synchronized(xx){
wait();//暂停
}
synchronized(xx){
notifyAll();//唤醒所有等待;
//notify()唤醒一个等待(不常用)
//lock:
Lock lock = new lock;
Condition condition = lock.newCondition();
lock.lock() ;
try{condition.await();//等待}catch(){}
//try{condition.signalAll();//唤醒}
finally{lock.unlock();//释放}
//同步队列:
//BolckingQueue put添加 take 释放 默认实现同步
//coutDownLatch:
CountDownLatch latch = new CountDownLatch(int);
latch.await();//等待
//latch.countDown(); int-1;当int为0时唤醒所有
网友评论