2018-04-12 多线程中的暂停,继续

2018-04-12  本文已影响0人  江江江123
//常用:
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时唤醒所有


上一篇下一篇

猜你喜欢

热点阅读