mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 12:12:08 +08:00
feature #I4R7AN 节点和Chain如何支持独有的线程池进行异步并发执行
This commit is contained in:
@@ -8,12 +8,13 @@
|
||||
*/
|
||||
package com.yomahub.liteflow.thread;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.yomahub.liteflow.exception.ThreadExecutorServiceCreateException;
|
||||
import com.yomahub.liteflow.property.LiteflowConfig;
|
||||
import com.yomahub.liteflow.util.SpringAware;
|
||||
import com.yomahub.liteflow.property.LiteflowConfigGetter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -32,8 +33,6 @@ public class ExecutorHelper {
|
||||
|
||||
private static ExecutorHelper executorHelper;
|
||||
|
||||
private ExecutorService executorService;
|
||||
|
||||
/**
|
||||
* 此处使用Map缓存线程池信息
|
||||
* key - 线程池构建者的Class全类名
|
||||
@@ -89,12 +88,12 @@ public class ExecutorHelper {
|
||||
* 构建全局默认线程池
|
||||
*/
|
||||
public ExecutorService buildExecutor() {
|
||||
if (ObjectUtil.isNull(executorService)) {
|
||||
LiteflowConfig liteflowConfig = SpringAware.getBean(LiteflowConfig.class);
|
||||
assert liteflowConfig != null;
|
||||
executorService = getExecutorBuilder(liteflowConfig.getThreadExecutorClass()).buildExecutor();
|
||||
LiteflowConfig liteflowConfig = LiteflowConfigGetter.get();
|
||||
if (!executorServiceMap.containsKey(liteflowConfig.getThreadExecutorClass())) {
|
||||
ExecutorService executorService = getExecutorBuilder(liteflowConfig.getThreadExecutorClass()).buildExecutor();
|
||||
executorServiceMap.put(liteflowConfig.getThreadExecutorClass(), executorService);
|
||||
}
|
||||
return executorService;
|
||||
return executorServiceMap.get(liteflowConfig.getThreadExecutorClass());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -138,14 +137,11 @@ public class ExecutorHelper {
|
||||
LOG.error(e.getMessage(), e);
|
||||
throw new ThreadExecutorServiceCreateException(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public ExecutorService getExecutorService() {
|
||||
return executorService;
|
||||
}
|
||||
|
||||
public void setExecutorService(ExecutorService executorService) {
|
||||
this.executorService = executorService;
|
||||
public void clearExecutorServiceMap(){
|
||||
if (MapUtil.isNotEmpty(executorServiceMap)){
|
||||
executorServiceMap.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.yomahub.liteflow.test;
|
||||
|
||||
import com.yomahub.liteflow.flow.FlowBus;
|
||||
import com.yomahub.liteflow.spring.ComponentScanner;
|
||||
import com.yomahub.liteflow.thread.ExecutorHelper;
|
||||
import org.junit.AfterClass;
|
||||
|
||||
public class BaseTest {
|
||||
@@ -10,5 +11,6 @@ public class BaseTest {
|
||||
public static void cleanScanCache(){
|
||||
ComponentScanner.cleanCache();
|
||||
FlowBus.cleanCache();
|
||||
ExecutorHelper.loadInstance().clearExecutorServiceMap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.yomahub.liteflow.test;
|
||||
|
||||
import com.yomahub.liteflow.flow.FlowBus;
|
||||
import com.yomahub.liteflow.spring.ComponentScanner;
|
||||
import com.yomahub.liteflow.thread.ExecutorHelper;
|
||||
import org.junit.AfterClass;
|
||||
|
||||
public class BaseTest {
|
||||
@@ -10,5 +11,6 @@ public class BaseTest {
|
||||
public static void cleanScanCache(){
|
||||
ComponentScanner.cleanCache();
|
||||
FlowBus.cleanCache();
|
||||
ExecutorHelper.loadInstance().clearExecutorServiceMap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,6 @@ public class BaseTest {
|
||||
public static void cleanScanCache(){
|
||||
ComponentScanner.cleanCache();
|
||||
FlowBus.cleanCache();
|
||||
ExecutorHelper.loadInstance().setExecutorService(null);
|
||||
ExecutorHelper.loadInstance().clearExecutorServiceMap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.yomahub.liteflow.test;
|
||||
|
||||
import com.yomahub.liteflow.flow.FlowBus;
|
||||
import com.yomahub.liteflow.spring.ComponentScanner;
|
||||
import com.yomahub.liteflow.thread.ExecutorHelper;
|
||||
import org.junit.AfterClass;
|
||||
|
||||
public class BaseTest {
|
||||
@@ -10,5 +11,6 @@ public class BaseTest {
|
||||
public static void cleanScanCache(){
|
||||
ComponentScanner.cleanCache();
|
||||
FlowBus.cleanCache();
|
||||
ExecutorHelper.loadInstance().clearExecutorServiceMap();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user