多线程实战2
3 月,跳不动了?>>> 固定个数的线程池,每个线程处理自己的任务 CountDownLatch countDownLatch = new CountDownLatch(maxThread); 来控制所有任务执行完成。 private static AtomicBoolean RUN_FLAG = new AtomicBoolean(false); private String singleHandler(int pageSize, Integer maxThread) { if (!RUN_FLAG.compareAndSet(false, true)) { log.info("【余额退出】任务进行中,不能再次执行"); return "任务进行中,不能再次执行"; } try { this.handler(pageSize, maxThread); return "处理完成"; } finally { RUN_FLAG.set(false); } } private void handler(int pageSize, Integer maxThread) { if (maxThread == null) { maxThread = 10; } final int maxThreads = maxThread; CountDownLatch countDownLatch =