diff --git a/hutool-core/src/main/java/cn/hutool/core/thread/ConcurrencyTester.java b/hutool-core/src/main/java/cn/hutool/core/thread/ConcurrencyTester.java
index 1accd2368..f0cdd33b5 100644
--- a/hutool-core/src/main/java/cn/hutool/core/thread/ConcurrencyTester.java
+++ b/hutool-core/src/main/java/cn/hutool/core/thread/ConcurrencyTester.java
@@ -2,6 +2,9 @@ package cn.hutool.core.thread;
import cn.hutool.core.date.TimeInterval;
+import java.io.Closeable;
+import java.io.IOException;
+
/**
* 高并发测试工具类
*
@@ -12,11 +15,14 @@ import cn.hutool.core.date.TimeInterval;
* ct.test(() -> {
* // 需要并发测试的业务代码
* });
+ *
+ * Console.log(ct.getInterval());
+ * ct.close();
*
*
* @author kwer
*/
-public class ConcurrencyTester {
+public class ConcurrencyTester implements Closeable {
private final SyncFinisher sf;
private final TimeInterval timeInterval;
private long interval;
@@ -31,7 +37,8 @@ public class ConcurrencyTester {
}
/**
- * 执行测试
+ * 执行测试
+ * 执行测试后不会关闭线程池,可以调用{@link #close()}释放线程池
*
* @param runnable 要测试的内容
* @return this
@@ -44,8 +51,6 @@ public class ConcurrencyTester {
.addRepeatWorker(runnable)
.setBeginAtSameTime(true)
.start();
- // 停止线程池释放资源,避免空跑
- this.sf.stop();
this.interval = timeInterval.interval();
return this;
@@ -76,4 +81,9 @@ public class ConcurrencyTester {
public long getInterval() {
return this.interval;
}
+
+ @Override
+ public void close() throws IOException {
+ this.sf.close();
+ }
}
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 18ad5fad5..512c0d89b 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
@@ -2,6 +2,8 @@ package cn.hutool.core.thread;
import cn.hutool.core.exceptions.UtilException;
+import java.io.Closeable;
+import java.io.IOException;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
@@ -25,7 +27,7 @@ import java.util.concurrent.ExecutorService;
* @author Looly
* @since 4.1.15
*/
-public class SyncFinisher {
+public class SyncFinisher implements Closeable {
private final Set workers;
private final int threadSize;
@@ -173,6 +175,11 @@ public class SyncFinisher {
return endLatch.getCount();
}
+ @Override
+ public void close() throws IOException {
+ stop();
+ }
+
/**
* 工作者,为一个线程
*