首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Condition引见

2013-12-11 
Condition介绍@Testpublic void testLock() { //thread mainfinal ReentrantLock rl new ReentrantLock(

Condition介绍
@Test public void testLock() { //thread main final ReentrantLock rl = new ReentrantLock(); final Condition newCondition = rl.newCondition(); new Thread(new Runnable() { // thread 1 @Override public void run() { rl.lock(); try { Thread.sleep(3000); newCondition.await(); } catch (InterruptedException e) { e.printStackTrace(); } rl.unlock(); } }).start(); new Thread(new Runnable() { //thread 2 @Override public void run() { try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } rl.lock(); newCondition.signal(); rl.unlock(); } }).start(); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } rl.lock(); try { newCondition.await(); } catch (InterruptedException e) { e.printStackTrace(); } rl.unlock(); }

?

?

?

热点排行