错误的例子:
@ThreadSafe
@Slf4j
public class AtomicExample6 {
// 总的请求个数
public static final int requestTotal = 1000;
// 同一时刻最大的并发线程的个数
public static final int concurrentThreadNum = 20;
private static Boolean isHappened_ = false;
public static void main(String[] args) throws InterruptedException {
ExecutorService executorService = Executors.newFixedThreadPool(concurrentThreadNum);
CountDownLatch countDownLatch = new CountDownLatch(requestTotal);
Semaphore semaphore = new Semaphore(concurrentThreadNum);
for (int i = 0; i< requestTotal; i++) {
executorService.execute(()->{
try {
semaphore.acquire();
test();
semaphore.rele