mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-19 21:48:10 +08:00
enhancement #I37QVR WhenCondition时候,并发执行目前会每次新建线程可不可走线程池
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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...");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user