码迷,mamicode.com
首页 > 其他好文 > 详细

3.1.5 倒计时器:CountDownLatch

时间:2018-02-07 11:54:36      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:rac   void   pre   runnable   class   3.1   str   tac   print   

package 第三章.倒计时器CountDownLatch;

import java.util.concurrent.CountDownLatch;

/**
* Created by zzq on 2018/1/24.
*/
public class CountDoenLatchTest implements Runnable{
static CountDownLatch countDownLatch=new CountDownLatch(3);
public void run() {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
countDownLatch.countDown();
}

public static void main(String[] args) throws InterruptedException {
CountDoenLatchTest countDoenLatchTest=new CountDoenLatchTest();
Thread thread=new Thread(countDoenLatchTest);
Thread thread2=new Thread(countDoenLatchTest);
Thread thread3=new Thread(countDoenLatchTest);
thread.start();
// thread2.start();
// thread3.start();
countDownLatch.await();
System.out.println("主线程执行----------");
}
}

3.1.5 倒计时器:CountDownLatch

标签:rac   void   pre   runnable   class   3.1   str   tac   print   

原文地址:https://www.cnblogs.com/anxbb/p/8425544.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!