重点作业重点工程相关
parent
c959c00e5a
commit
90921a0da1
|
|
@ -49,3 +49,11 @@ openapi:
|
|||
apiCode: test:01
|
||||
#多个可以逗号隔开,可以为空
|
||||
tenantIds: 1838408702262321152
|
||||
archives:
|
||||
async:
|
||||
pool:
|
||||
maxPoolSize: 2
|
||||
corePoolSize: 1
|
||||
queueCapacity: 60
|
||||
namePrefix: async-task-
|
||||
keepAliveSeconds: 60
|
||||
|
|
@ -49,3 +49,11 @@ openapi:
|
|||
apiCode: test:01
|
||||
#多个可以逗号隔开,可以为空
|
||||
tenantIds: 1838408702262321152
|
||||
archives:
|
||||
async:
|
||||
pool:
|
||||
maxPoolSize: 2
|
||||
corePoolSize: 1
|
||||
queueCapacity: 60
|
||||
namePrefix: async-task-
|
||||
keepAliveSeconds: 60
|
||||
|
|
@ -67,6 +67,7 @@ public class MessageNoticeExe {
|
|||
log.error("{},消息提醒发送消息异常:", sourceCode,e);
|
||||
}
|
||||
}
|
||||
@Async("asyncExecutor")
|
||||
public void sendMessageAddEvent(Long userId, String title,String content, Long foreignKey) {
|
||||
//消息通知
|
||||
try{
|
||||
|
|
@ -81,6 +82,8 @@ public class MessageNoticeExe {
|
|||
event.setAppFlag(1); // 是否APP端待办 1是 0否
|
||||
event.setOtherParams(new JSONObject());
|
||||
log.info("待办,请求:{}",event);
|
||||
//为了防止先被完成
|
||||
Thread.sleep(2000L);
|
||||
boolean b = todoListEventPusherUtil.sendMessageAddEvent(event);
|
||||
log.info("待办,结果:{}",b);
|
||||
}catch (Exception e) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,76 @@
|
|||
package com.zcloud.key.project.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
/**
|
||||
* @author zhangyue
|
||||
* @date 2026/2/2 17:24
|
||||
*/
|
||||
|
||||
@Configuration
|
||||
public class ThreadPoolAsyncConfig {
|
||||
|
||||
|
||||
public static Integer maxPoolSize;
|
||||
public static Integer corePoolSize;
|
||||
public static Integer queueCapacity;
|
||||
public static String namePrefix;
|
||||
public static Integer keepAliveSeconds;
|
||||
|
||||
@Value("${archives.async.pool.maxPoolSize}")
|
||||
public void setMaxPoolSize(Integer maxPoolSizeProperties) {
|
||||
maxPoolSize = maxPoolSizeProperties;
|
||||
}
|
||||
|
||||
@Value("${archives.async.pool.corePoolSize}")
|
||||
public void setCorePoolSize(Integer corePoolSizeProperties) {
|
||||
corePoolSize = corePoolSizeProperties;
|
||||
}
|
||||
|
||||
@Value("${archives.async.pool.queueCapacity}")
|
||||
public void setQueueCapacity(Integer queueCapacityProperties) {
|
||||
queueCapacity = queueCapacityProperties;
|
||||
}
|
||||
|
||||
@Value("${archives.async.pool.namePrefix}")
|
||||
public void setNamePrefix(String namePrefixProperties) {
|
||||
namePrefix = namePrefixProperties;
|
||||
}
|
||||
|
||||
@Value("${archives.async.pool.keepAliveSeconds}")
|
||||
public void setKeepAliveSeconds(Integer keepAliveSecondsProperties) {
|
||||
keepAliveSeconds = keepAliveSecondsProperties;
|
||||
}
|
||||
|
||||
@Bean()
|
||||
public Executor asyncExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
//最大线程数
|
||||
executor.setMaxPoolSize(maxPoolSize);
|
||||
//核心线程数
|
||||
executor.setCorePoolSize(corePoolSize);
|
||||
//任务队列的大小
|
||||
executor.setQueueCapacity(queueCapacity);
|
||||
//线程前缀名
|
||||
executor.setThreadNamePrefix(namePrefix);
|
||||
//线程存活时间
|
||||
executor.setKeepAliveSeconds(keepAliveSeconds);
|
||||
/**
|
||||
* 拒绝处理策略
|
||||
* CallerRunsPolicy():交由调用方线程运行,比如 main 线程。
|
||||
* AbortPolicy():直接抛出异常。
|
||||
* DiscardPolicy():直接丢弃。
|
||||
* DiscardOldestPolicy():丢弃队列中最老的任务。
|
||||
*/
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
|
||||
// 初始化
|
||||
executor.initialize();
|
||||
return executor;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue