diff --git a/hutool-core/src/main/java/cn/hutool/core/thread/SyncFinisher.java b/hutool-core/src/main/java/cn/hutool/core/thread/SyncFinisher.java index ae49c0e22..ebdee040a 100644 --- a/hutool-core/src/main/java/cn/hutool/core/thread/SyncFinisher.java +++ b/hutool-core/src/main/java/cn/hutool/core/thread/SyncFinisher.java @@ -23,7 +23,6 @@ import java.util.concurrent.ExecutorService; * sf.start() * * - * * @author Looly * @since 4.1.15 */ @@ -34,9 +33,13 @@ public class SyncFinisher implements Closeable { private ExecutorService executorService; private boolean isBeginAtSameTime; - /** 启动同步器,用于保证所有worker线程同时开始 */ + /** + * 启动同步器,用于保证所有worker线程同时开始 + */ private final CountDownLatch beginLatch; - /** 结束同步器,用于等待所有worker线程同时结束 */ + /** + * 结束同步器,用于等待所有worker线程同时结束 + */ private CountDownLatch endLatch; /** @@ -123,7 +126,7 @@ public class SyncFinisher implements Closeable { public void start(final boolean sync) { endLatch = new CountDownLatch(workers.size()); - if(null == this.executorService || this.executorService.isShutdown()){ + if (null == this.executorService || this.executorService.isShutdown()) { this.executorService = ThreadUtil.newExecutor(threadSize); } for (final Worker worker : workers) { @@ -150,9 +153,27 @@ public class SyncFinisher implements Closeable { * * @since 5.6.6 */ - public void stop(){ - if(null != this.executorService){ - this.executorService.shutdown(); + public void stop() { + stop(false); + } + + /** + * 结束线程池。此方法执行两种情况: + *