enhancement #I37QVR WhenCondition时候,并发执行目前会每次新建线程可不可走线程池

This commit is contained in:
徐佳
2021-03-25 17:22:45 +08:00
parent 32026989e1
commit 47fe94b2b4
38 changed files with 1200 additions and 14 deletions

View File

@@ -0,0 +1,38 @@
package com.yomahub.liteflow.springboot;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.concurrent.ExecutorService;
import static com.yomahub.liteflow.util.ExecutorHelper.buildExecutor;
/**
* desc :
* name : LiteflowExecutorAutoConfiguration
*
* @author : xujia
* date : 2021/3/24
* @since : 1.8
*/
@Configuration
public class LiteflowExecutorAutoConfiguration {
@Bean("parallelExecutor")
public ExecutorService parallelExecutor(
@Value("${threadPool.parallel.worker:0}") int worker,
@Value("${threadPool.parallel.queue:512}") int queue) {
int useWorker = worker;
int useQueue = queue;
if (useWorker == 0) {
useWorker = Runtime.getRuntime().availableProcessors() + 1;
}
if (useQueue < 512) {
useQueue = 512;
}
return buildExecutor(useWorker, useQueue, "parallel-executors", false);
}
}

View File

@@ -20,6 +20,7 @@ import org.springframework.context.annotation.PropertySource;
import javax.swing.*;
import java.util.List;
import java.util.concurrent.ExecutorService;
/**
* 主要的业务装配器
@@ -29,15 +30,16 @@ import java.util.List;
*/
@Configuration
@ConditionalOnBean(LiteflowConfig.class)
@AutoConfigureAfter(LiteflowPropertyAutoConfiguration.class)
@AutoConfigureAfter({LiteflowPropertyAutoConfiguration.class, LiteflowExecutorAutoConfiguration.class})
@Import(SpringAware.class)
public class LiteflowMainAutoConfiguration {
@Bean
public FlowExecutor flowExecutor(LiteflowConfig liteflowConfig){
public FlowExecutor flowExecutor(LiteflowConfig liteflowConfig, ExecutorService parallelExecutor){
if(StrUtil.isNotBlank(liteflowConfig.getRuleSource())){
FlowExecutor flowExecutor = new FlowExecutor();
flowExecutor.setLiteflowConfig(liteflowConfig);
flowExecutor.setParallelExecutor(parallelExecutor);
return flowExecutor;
}else{
return null;

View File

@@ -0,0 +1,37 @@
package com.yomahub.liteflow.springboot;
import com.yomahub.liteflow.util.ExecutorHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import java.util.concurrent.ExecutorService;
/**
* desc :
* name : Shutdown
*
* @author : xujia
* date : 2021/3/24
* @since : 1.8
*/
@Order(Integer.MIN_VALUE)
@Component
public class Shutdown {
private static final Logger LOG = LoggerFactory.getLogger(Shutdown.class);
@Resource(name = "parallelExecutor")
private ExecutorService parallelExecutor;
@PreDestroy
public void destroy() throws Exception {
LOG.info("Start closing the parallel-executors...");
ExecutorHelper.shutdownAwaitTermination(parallelExecutor, 3600);
LOG.info("Succeed closing the parallel-executors ok...");
}
}