SyncFinisher线程同步结束器添加立即结束方法

This commit is contained in:
Looly 2022-11-26 12:13:39 +08:00
parent 8767b1edc1
commit d29b87c36f
2 changed files with 16 additions and 12 deletions

View File

@ -7,6 +7,8 @@
### 🐣新特性
* 【core 】 CharUtil.isBlankChar增加\u180epr#2738@Github
* 【core 】 SyncFinisher线程同步结束器添加立即结束方法pr#879@Gitee
*
### 🐞Bug修复
* 【json 】 修复普通byte数组转JSONArray时的异常pr#875@Gitee
* 【core 】 修复ArrayUtil.insert()不支持原始类型数组的问题pr#874@Gitee

View File

@ -23,7 +23,6 @@ import java.util.concurrent.ExecutorService;
* sf.start()
* </pre>
*
*
* @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(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 (Worker worker : workers) {
@ -150,11 +153,11 @@ public class SyncFinisher implements Closeable {
*
* @since 5.6.6
*/
public void stop(){
if(null != this.executorService){
public void stop() {
if (null != this.executorService) {
this.executorService.shutdown();
this.executorService = null;
}
this.executorService = null;
clearWorker();
}
@ -166,13 +169,13 @@ public class SyncFinisher implements Closeable {
* <li>执行start(false)用户自行判断结束点执行此方法</li>
* </ol>
*
* @since 5.6.6
* @since 5.8.11
*/
public void stopNow(){
if(null != this.executorService){
public void stopNow() {
if (null != this.executorService) {
this.executorService.shutdownNow();
this.executorService = null;
}
this.executorService = null;
clearWorker();
}
@ -202,7 +205,6 @@ public class SyncFinisher implements Closeable {
* 工作者为一个线程
*
* @author xiaoleilu
*
*/
public abstract class Worker implements Runnable {