update - 实用 @Async 注解,并自定义线程池
This commit is contained in:
parent
a9abc1add3
commit
dbaa74480f
@ -0,0 +1,10 @@
|
||||
package cn.axzo.workflow.core.common.context;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*
|
||||
* @author wangli
|
||||
* @since 2024/4/9 22:52
|
||||
*/
|
||||
public class ProcessOperationContext extends CommonContext<ProcessOperationContext> {
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
package cn.axzo.workflow.core.conf;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.AsyncConfigurerSupport;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*
|
||||
* @author wangli
|
||||
* @since 2024/4/9 23:10
|
||||
*/
|
||||
@Configuration
|
||||
@EnableAsync
|
||||
@Slf4j
|
||||
public class SpringAsyncConfigurer extends AsyncConfigurerSupport {
|
||||
|
||||
@Bean
|
||||
public ThreadPoolTaskExecutor asyncExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
//核心线程池大小
|
||||
executor.setCorePoolSize(5);
|
||||
//最大线程数
|
||||
executor.setMaxPoolSize(10);
|
||||
//队列容量
|
||||
executor.setQueueCapacity(200);
|
||||
//活跃时间
|
||||
executor.setKeepAliveSeconds(60);
|
||||
//线程名字前缀
|
||||
executor.setThreadNamePrefix("async-executor-");
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
return executor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Executor getAsyncExecutor() {
|
||||
return asyncExecutor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
|
||||
return (ex, method, params) -> log.info(String.format("执行异步任务'%s'", method), ex);
|
||||
}
|
||||
}
|
||||
@ -16,7 +16,8 @@ public interface BpmnMessagePushEventListener extends Ordered {
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
default void onNotice(MessagePushEvent event) {}
|
||||
default void onNotice(MessagePushEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送待办
|
||||
@ -40,7 +41,6 @@ public interface BpmnMessagePushEventListener extends Ordered {
|
||||
* @param event
|
||||
*/
|
||||
default void onCarbonCopy(MessagePushEvent event) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -48,5 +48,6 @@ public interface BpmnMessagePushEventListener extends Ordered {
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
default void onSms(MessagePushEvent event) {}
|
||||
default void onSms(MessagePushEvent event) {
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,7 +5,6 @@ import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
|
||||
@ -13,7 +12,6 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
@ComponentScan({"cn.axzo.workflow", "cn.axzo.maokai"})
|
||||
@SpringBootApplication(exclude = RabbitAutoConfiguration.class)
|
||||
@EnableTransactionManagement
|
||||
@EnableAsync
|
||||
public class WorkflowEnginApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package cn.axzo.workflow.server.controller.listener.process;
|
||||
|
||||
import cn.axzo.workflow.common.model.request.bpmn.BpmnNoticeConf;
|
||||
import cn.axzo.workflow.core.common.context.ProcessOperationContext;
|
||||
import cn.axzo.workflow.core.common.utils.BpmnMetaParserHelper;
|
||||
import cn.axzo.workflow.core.engine.event.MessagePushEventBuilder;
|
||||
import cn.axzo.workflow.core.engine.event.MessagePushEventImpl;
|
||||
@ -29,7 +30,7 @@ import java.util.Optional;
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class MessagePushProcessEventListener extends AbstractBpmnEventListener implements BpmnProcessEventListener, Ordered {
|
||||
public class MessagePushProcessEventListener extends AbstractBpmnEventListener<ProcessOperationContext> implements BpmnProcessEventListener, Ordered {
|
||||
|
||||
@Override
|
||||
public void onCancelled(FlowableCancelledEvent event) {
|
||||
|
||||
@ -5,6 +5,7 @@ import cn.axzo.framework.rocketmq.EventProducer;
|
||||
import cn.axzo.workflow.common.enums.ProcessInstanceEventEnum;
|
||||
import cn.axzo.workflow.common.model.request.bpmn.task.BpmnTaskDelegateAssigner;
|
||||
import cn.axzo.workflow.common.model.response.mq.ProcessInstanceDTO;
|
||||
import cn.axzo.workflow.core.common.context.ProcessOperationContext;
|
||||
import cn.axzo.workflow.core.common.utils.BpmnMetaParserHelper;
|
||||
import cn.axzo.workflow.core.listener.AbstractBpmnEventListener;
|
||||
import cn.axzo.workflow.core.listener.BpmnProcessEventListener;
|
||||
@ -45,7 +46,7 @@ import static cn.axzo.workflow.common.enums.ProcessInstanceEventEnum.PROCESS_INS
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class RocketMqBpmnProcessEventListener extends AbstractBpmnEventListener implements BpmnProcessEventListener, Ordered {
|
||||
public class RocketMqBpmnProcessEventListener extends AbstractBpmnEventListener<ProcessOperationContext> implements BpmnProcessEventListener, Ordered {
|
||||
@Resource
|
||||
private RuntimeService runtimeService;
|
||||
@Resource
|
||||
|
||||
Loading…
Reference in New Issue
Block a user