feature #I4E5NX 异步线程池自定义

This commit is contained in:
bryan31
2021-12-10 23:47:07 +08:00
parent 94760b9f21
commit 8ca854c188
29 changed files with 452 additions and 52 deletions

View File

@@ -21,6 +21,9 @@ public class LiteflowProperty {
//slot的数量
private int slotSize;
//并行线程执行器class路径
private String threadExecutorClass;
//异步线程最大等待描述
private int whenMaxWaitSeconds;
@@ -131,4 +134,12 @@ public class LiteflowProperty {
public void setPrintBanner(boolean printBanner) {
this.printBanner = printBanner;
}
public String getThreadExecutorClass() {
return threadExecutorClass;
}
public void setThreadExecutorClass(String threadExecutorClass) {
this.threadExecutorClass = threadExecutorClass;
}
}

View File

@@ -1,7 +1,7 @@
package com.yomahub.liteflow.springboot.config;
import com.yomahub.liteflow.property.LiteflowConfig;
import com.yomahub.liteflow.util.ExecutorHelper;
import com.yomahub.liteflow.thread.ExecutorHelper;
import com.yomahub.liteflow.util.LiteFlowExecutorPoolShutdown;
import com.yomahub.liteflow.util.SpringAware;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
@@ -30,7 +30,14 @@ public class LiteflowExecutorAutoConfiguration {
return ExecutorHelper.loadInstance().buildExecutor();
}
@Bean
//为什么要注释掉这个@Bean
//LiteFlowExecutorPoolShutdown这个类会在spring上下文移除这个bean的时候执行也就是应用被停止或者kill的时候
//这个类主要用于卸载掉线程池,会等待线程池中的线程执行完,再卸载掉,相当于一个钩子
//但这段代码在实际中并没有太多用户,就算结束掉应用进程时很多公司也会优雅停机。就显得这段代码很鸡肋
//之所以注释掉是因为在单元测试中每一个testcase结束时都会调这个方法。
//当异步线程配置超时的时候。由于这个方法会去关闭掉线程池,会导致单元测试在所有一起运行时(单个运行没有问题)会出错
//按理说这个方法会等待线程池里的全部线程执行完再销毁,但是事实上在单元测试中的确会报错。具体原因还没深究,由于这个类比较鸡肋,就干脆不注册了。
//@Bean
public LiteFlowExecutorPoolShutdown liteFlowExecutorPoolShutdown() {
return new LiteFlowExecutorPoolShutdown();
}

View File

@@ -27,6 +27,7 @@ public class LiteflowPropertyAutoConfiguration {
LiteflowConfig liteflowConfig = new LiteflowConfig();
liteflowConfig.setRuleSource(property.getRuleSource());
liteflowConfig.setSlotSize(property.getSlotSize());
liteflowConfig.setThreadExecutorClass(property.getThreadExecutorClass());
liteflowConfig.setWhenMaxWaitSeconds(property.getWhenMaxWaitSeconds());
liteflowConfig.setEnableLog(liteflowMonitorProperty.isEnableLog());
liteflowConfig.setQueueLimit(liteflowMonitorProperty.getQueueLimit());

View File

@@ -30,6 +30,12 @@
"description": "Node definition for ZK configuration.",
"sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty"
},
{
"name": "liteflow.thread-executor-class",
"type": "java.lang.String",
"description": "Multi thread pool.",
"sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty"
},
{
"name": "liteflow.when-max-wait-seconds",
"type": "java.lang.Integer",

View File

@@ -3,6 +3,7 @@ liteflow.print-banner=true
liteflow.rule-source=config/flow.xml
liteflow.zk-node=/lite-flow/flow
liteflow.slot-size=1024
liteflow.thread-executor-class=com.yomahub.liteflow.thread.LiteFlowDefaultExecutorBuilder
liteflow.when-max-wait-seconds=15
liteflow.when-max-workers=16
liteflow.when-queue-limit=512