1.线程类
package com.wlg;
import java.util.concurrent.Phaser;
public class MyThread extends Thread {
public Phaser phaserser;
public MyThread( Phaser phaserser) {
this.phaserser = phaserser;
}
@Override
public void run() {
System.out.println("线程"+Thread.currentThread().getName()+"到达屏障开始等待时间:"+System.currentTimeMillis());
phaserser.arriveAndAwaitAdvance();
System.out.println("线程"+Thread.currentThread().getName()+"通过屏障时间:"+System.currentTimeMillis());
}
}
2.测试方法,给Phaser对象设置parties为2,每隔5秒分别启动ABC3个线程,具体教程请参考:http://www.yayihouse.com/yayishuwu/chapter/2576