标签:art over test ati width port catch 线程 完成
package t1;
import java.util.concurrent.CyclicBarrier;
public class TestThread26 extends Thread {
private CyclicBarrier cy;
public TestThread26(CyclicBarrier cy) {
this.cy = cy;
}
@Override
public void run() {
try {
System.out.println(Thread.currentThread().getName() + "开始等待其他线程");
cy.await();
System.out.println(Thread.currentThread().getName() + "开始执行");
Thread.sleep(2000);
System.out.println(Thread.currentThread().getName() + "执行完成");
} catch (Exception e) {
}
}
public static void main(String[] args) {
int cnt = 2;
CyclicBarrier cy = new CyclicBarrier(2);
for (int i = 0; i < cnt; i++) {
System.out.println("创建工作线程" + i);
TestThread26 t = new TestThread26(cy);
t.start();
}
}
}
测试结果:
标签:art over test ati width port catch 线程 完成
原文地址:https://www.cnblogs.com/dengw125792/p/12613266.html