This commit is contained in:
Looly 2021-05-14 16:58:33 +08:00
parent 415b2a285f
commit 2c1d10d952
3 changed files with 45 additions and 21 deletions

View File

@ -3,11 +3,12 @@
-------------------------------------------------------------------------------------------------------------
# 5.6.6 (2021-05-11)
# 5.6.6 (2021-05-14)
### 🐣新特性
* 【cron 】 增加时间轮简单实现
* 【core 】 BeanUtil.copyToList增加重载pr#321@Gitee
* 【core 】 SyncFinisher增加stop方法issue#1578@Github
### 🐞Bug修复

View File

@ -30,7 +30,7 @@ public class SyncFinisher {
private final Set<Worker> workers;
private final int threadSize;
private final ExecutorService executorService;
private ExecutorService executorService;
private boolean isBeginAtSameTime;
/** 启动同步器用于保证所有worker线程同时开始 */
@ -46,7 +46,6 @@ public class SyncFinisher {
public SyncFinisher(int threadSize) {
this.beginLatch = new CountDownLatch(1);
this.threadSize = threadSize;
this.executorService = ThreadUtil.newExecutor(threadSize);
this.workers = new LinkedHashSet<>();
}
@ -106,20 +105,26 @@ public class SyncFinisher {
}
/**
* 开始工作
* 开始工作<br>
* 执行此方法后如果不再重复使用此对象需调用{@link #stop()}关闭回收资源
*/
public void start() {
start(true);
}
/**
* 开始工作
* 开始工作<br>
* 执行此方法后如果不再重复使用此对象需调用{@link #stop()}关闭回收资源
*
* @param sync 是否阻塞等待
* @since 4.5.8
*/
public void start(boolean sync) {
endLatch = new CountDownLatch(workers.size());
if(null == this.executorService || this.executorService.isShutdown()){
this.executorService = ThreadUtil.newExecutor(threadSize);
}
for (Worker worker : workers) {
executorService.submit(worker);
}
@ -135,6 +140,24 @@ public class SyncFinisher {
}
}
/**
* 结束线程池此方法执行两种情况
* <ol>
* <li>执行start(true)调用此方法结束线程池回收资源</li>
* <li>执行start(false)用户自行判断结束点执行此方法</li>
* </ol>
*
* @since 5.6.6
*/
public void stop(){
if(null != this.executorService){
this.executorService.shutdown();
}
this.executorService = null;
clearWorker();
}
/**
* 等待所有Worker工作结束否则阻塞
*