1700451681
1700451682
public Runner(CountDownLatch_begin, CountDownLatch_end){
1700451683
1700451684
begin=_begin;
1700451685
1700451686
end=_end;
1700451687
1700451688
}
1700451689
1700451690
@Override
1700451691
1700451692
public Integer call()throws Exception{
1700451693
1700451694
//跑步的成绩
1700451695
1700451696
int score=new Random().nextInt(25);
1700451697
1700451698
//等待发令枪响起
1700451699
1700451700
begin.await();
1700451701
1700451702
//跑步中……
1700451703
1700451704
TimeUnit.MILLISECONDS.sleep(score);
1700451705
1700451706
//跑步者已经跑完全程
1700451707
1700451708
end.countDown();
1700451709
1700451710
return score;
1700451711
1700451712
}
1700451713
1700451714
}
1700451715
1700451716
public static void main(String[]args)throws Exception{
1700451717
1700451718
//参加赛跑人数
1700451719
1700451720
int num=10;
1700451721
1700451722
//发令枪只响一次
1700451723
1700451724
CountDownLatch begin=new CountDownLatch(1);
1700451725
1700451726
//参与跑步有多个
1700451727
1700451728
CountDownLatch end=new CountDownLatch(num);
1700451729
1700451730
//每个跑步者一个跑道
[
上一页 ]
[ :1.700451681e+09 ]
[
下一页 ]