mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix code
This commit is contained in:
parent
3938b2b97c
commit
b82496befd
@ -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(final 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 (final Worker worker : workers) {
|
||||
@ -150,9 +153,27 @@ public class SyncFinisher implements Closeable {
|
||||
*
|
||||
* @since 5.6.6
|
||||
*/
|
||||
public void stop(){
|
||||
if(null != this.executorService){
|
||||
this.executorService.shutdown();
|
||||
public void stop() {
|
||||
stop(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 结束线程池。此方法执行两种情况:
|
||||
* <ol>
|
||||
* <li>执行start(true)后,调用此方法结束线程池回收资源</li>
|
||||
* <li>执行start(false)后,用户自行判断结束点执行此方法</li>
|
||||
* </ol>
|
||||
*
|
||||
* @param isStopNow 是否立即结束所有线程(包括正在执行的)
|
||||
* @since 5.6.6
|
||||
*/
|
||||
public void stop(final boolean isStopNow) {
|
||||
if (null != this.executorService) {
|
||||
if (isStopNow) {
|
||||
this.executorService.shutdownNow();
|
||||
} else {
|
||||
this.executorService.shutdown();
|
||||
}
|
||||
}
|
||||
this.executorService = null;
|
||||
|
||||
@ -184,7 +205,6 @@ public class SyncFinisher implements Closeable {
|
||||
* 工作者,为一个线程
|
||||
*
|
||||
* @author xiaoleilu
|
||||
*
|
||||
*/
|
||||
public abstract class Worker implements Runnable {
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user