-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestCyclicBarrier.java
More file actions
35 lines (31 loc) · 1013 Bytes
/
TestCyclicBarrier.java
File metadata and controls
35 lines (31 loc) · 1013 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.zyj;
import java.util.concurrent.CyclicBarrier;
/**
* 版权声明:CopyRight (c) 2018 ucarinc. All Rights Reserved.
*
* @author : 张勇杰
* @date : 2019/3/12 15:46
* @Version : v1.0
* @description
**/
public class TestCyclicBarrier {
public static CyclicBarrier cyclicBarrier = new CyclicBarrier(4);
public static void main(String[] args) {
for (int i = 0 ;i<4;i++){
new NewThread().start();
}
}
static class NewThread extends Thread{
@Override
public void run() {
try{
System.out.println(Thread.currentThread().getName()+"开始执行.....");
Thread.sleep(5000);
System.out.println(Thread.currentThread().getName()+"执行完毕,等待其他线程执行");
cyclicBarrier.await();
}catch (Exception e){
}
System.out.println(Thread.currentThread().getName()+"开始做接下来的事情.....");
}
}
}