mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-30 12:47:58 +08:00
SyncFinisher线程同步结束器添加立即结束方法
This commit is contained in:
parent
8767b1edc1
commit
d29b87c36f
@ -7,6 +7,8 @@
|
||||
|
||||
### 🐣新特性
|
||||
* 【core 】 CharUtil.isBlankChar增加\u180e(pr#2738@Github)
|
||||
* 【core 】 SyncFinisher线程同步结束器添加立即结束方法(pr#879@Gitee)
|
||||
*
|
||||
### 🐞Bug修复
|
||||
* 【json 】 修复普通byte数组转JSONArray时的异常(pr#875@Gitee)
|
||||
* 【core 】 修复ArrayUtil.insert()不支持原始类型数组的问题(pr#874@Gitee)
|
||||
|
@ -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 {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user