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()
|
* sf.start()
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @author Looly
|
* @author Looly
|
||||||
* @since 4.1.15
|
* @since 4.1.15
|
||||||
*/
|
*/
|
||||||
@ -34,9 +33,13 @@ public class SyncFinisher implements Closeable {
|
|||||||
private ExecutorService executorService;
|
private ExecutorService executorService;
|
||||||
|
|
||||||
private boolean isBeginAtSameTime;
|
private boolean isBeginAtSameTime;
|
||||||
/** 启动同步器,用于保证所有worker线程同时开始 */
|
/**
|
||||||
|
* 启动同步器,用于保证所有worker线程同时开始
|
||||||
|
*/
|
||||||
private final CountDownLatch beginLatch;
|
private final CountDownLatch beginLatch;
|
||||||
/** 结束同步器,用于等待所有worker线程同时结束 */
|
/**
|
||||||
|
* 结束同步器,用于等待所有worker线程同时结束
|
||||||
|
*/
|
||||||
private CountDownLatch endLatch;
|
private CountDownLatch endLatch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -123,7 +126,7 @@ public class SyncFinisher implements Closeable {
|
|||||||
public void start(final boolean sync) {
|
public void start(final boolean sync) {
|
||||||
endLatch = new CountDownLatch(workers.size());
|
endLatch = new CountDownLatch(workers.size());
|
||||||
|
|
||||||
if(null == this.executorService || this.executorService.isShutdown()){
|
if (null == this.executorService || this.executorService.isShutdown()) {
|
||||||
this.executorService = ThreadUtil.newExecutor(threadSize);
|
this.executorService = ThreadUtil.newExecutor(threadSize);
|
||||||
}
|
}
|
||||||
for (final Worker worker : workers) {
|
for (final Worker worker : workers) {
|
||||||
@ -150,9 +153,27 @@ public class SyncFinisher implements Closeable {
|
|||||||
*
|
*
|
||||||
* @since 5.6.6
|
* @since 5.6.6
|
||||||
*/
|
*/
|
||||||
public void stop(){
|
public void stop() {
|
||||||
if(null != this.executorService){
|
stop(false);
|
||||||
this.executorService.shutdown();
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 结束线程池。此方法执行两种情况:
|
||||||
|
* <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;
|
this.executorService = null;
|
||||||
|
|
||||||
@ -184,7 +205,6 @@ public class SyncFinisher implements Closeable {
|
|||||||
* 工作者,为一个线程
|
* 工作者,为一个线程
|
||||||
*
|
*
|
||||||
* @author xiaoleilu
|
* @author xiaoleilu
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public abstract class Worker implements Runnable {
|
public abstract class Worker implements Runnable {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user