package com.nwk.juc;
import java.util.UUID;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.Semaphore;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
public class sunxu {
public static void main1(String[] args) {
CyclicBarrier cyclicBarrier = new CyclicBarrier(2);
CyclicBarrier cyclicBarrier2 = new CyclicBarrier(2);
cyclicBarrier.reset();
Runnable runnable = () -> {
try {
cyclicBarrier.await();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (BrokenBarrierException e) {
e.printStackTrace();
}
System.out.println("1");
};
new Thread(runnable).start();
new Thread(() -> {
try {
cyclicBarrier2.await();
System.out.println("2"
4种保证三个线程按顺序致行的方法
最新推荐文章于 2024-06-11 10:37:49 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)