mirror of
https://gitee.com/dromara/hutool.git
synced 2025-07-15 05:13:18 +08:00
add stop
This commit is contained in:
parent
415b2a285f
commit
2c1d10d952
@ -3,11 +3,12 @@
|
|||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
# 5.6.6 (2021-05-11)
|
# 5.6.6 (2021-05-14)
|
||||||
|
|
||||||
### 🐣新特性
|
### 🐣新特性
|
||||||
* 【cron 】 增加时间轮简单实现
|
* 【cron 】 增加时间轮简单实现
|
||||||
* 【core 】 BeanUtil.copyToList增加重载(pr#321@Gitee)
|
* 【core 】 BeanUtil.copyToList增加重载(pr#321@Gitee)
|
||||||
|
* 【core 】 SyncFinisher增加stop方法(issue#1578@Github)
|
||||||
|
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ public class SyncFinisher {
|
|||||||
|
|
||||||
private final Set<Worker> workers;
|
private final Set<Worker> workers;
|
||||||
private final int threadSize;
|
private final int threadSize;
|
||||||
private final ExecutorService executorService;
|
private ExecutorService executorService;
|
||||||
|
|
||||||
private boolean isBeginAtSameTime;
|
private boolean isBeginAtSameTime;
|
||||||
/** 启动同步器,用于保证所有worker线程同时开始 */
|
/** 启动同步器,用于保证所有worker线程同时开始 */
|
||||||
@ -46,7 +46,6 @@ public class SyncFinisher {
|
|||||||
public SyncFinisher(int threadSize) {
|
public SyncFinisher(int threadSize) {
|
||||||
this.beginLatch = new CountDownLatch(1);
|
this.beginLatch = new CountDownLatch(1);
|
||||||
this.threadSize = threadSize;
|
this.threadSize = threadSize;
|
||||||
this.executorService = ThreadUtil.newExecutor(threadSize);
|
|
||||||
this.workers = new LinkedHashSet<>();
|
this.workers = new LinkedHashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,20 +105,26 @@ public class SyncFinisher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 开始工作
|
* 开始工作<br>
|
||||||
|
* 执行此方法后如果不再重复使用此对象,需调用{@link #stop()}关闭回收资源。
|
||||||
*/
|
*/
|
||||||
public void start() {
|
public void start() {
|
||||||
start(true);
|
start(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 开始工作
|
* 开始工作<br>
|
||||||
|
* 执行此方法后如果不再重复使用此对象,需调用{@link #stop()}关闭回收资源。
|
||||||
*
|
*
|
||||||
* @param sync 是否阻塞等待
|
* @param sync 是否阻塞等待
|
||||||
* @since 4.5.8
|
* @since 4.5.8
|
||||||
*/
|
*/
|
||||||
public void start(boolean sync) {
|
public void start(boolean sync) {
|
||||||
endLatch = new CountDownLatch(workers.size());
|
endLatch = new CountDownLatch(workers.size());
|
||||||
|
|
||||||
|
if(null == this.executorService || this.executorService.isShutdown()){
|
||||||
|
this.executorService = ThreadUtil.newExecutor(threadSize);
|
||||||
|
}
|
||||||
for (Worker worker : workers) {
|
for (Worker worker : workers) {
|
||||||
executorService.submit(worker);
|
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工作结束,否则阻塞
|
* 等待所有Worker工作结束,否则阻塞
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user