CountDownLatch 减法
CountDownLatch countDownLatch = new CountDownLatch(6);
countDownLatch.countDown();
countDownLatch.await();
CyclicBarrier 加法
CyclicBarrier cyclicBarrier = new CyclicBarrier(7, () -> {
System.out.println("执行7条线程后才会执行这里");
});
for (int i = 1;i<8;i++){
new Thread(()->{
cyclicBarrier.await();
}).start();
}
Semaphore 限流
Semaphore semaphore = new Semaphore(3);
for(int i = 1 ; i<7;i++){
new Thread(()->{
try {
semaphore.acquire();
} catch (InterruptedException e) {
e.printStackTrace();
}finally {
semaphore.release();
}
}).start();
}