forked from Gitlink/soft_bot
64 lines
2.3 KiB
Java
64 lines
2.3 KiB
Java
package com.gitlink.softbot.config;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.scheduling.annotation.EnableAsync;
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
import java.util.concurrent.Executor;
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
|
|
|
|
@Configuration
|
|
@EnableAsync
|
|
public class MyThreadPoolConfig {
|
|
|
|
|
|
@Bean("addWebhookTaskExecutor")
|
|
public Executor addWebhookTaskExecutor() {
|
|
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
|
executor.setCorePoolSize(10);
|
|
executor.setMaxPoolSize(20);
|
|
// 设置队列容量
|
|
executor.setQueueCapacity(200);
|
|
// 设置线程活跃时间(秒)
|
|
executor.setKeepAliveSeconds(60);
|
|
executor.setThreadNamePrefix("AddWebhook_Async-Service-");
|
|
// 设置拒绝策略
|
|
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
|
executor.initialize();
|
|
return executor;
|
|
}
|
|
|
|
@Bean("deleteWebhookTaskExecutor")
|
|
public Executor deleteWebhookTaskExecutor() {
|
|
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
|
executor.setCorePoolSize(5);
|
|
executor.setMaxPoolSize(10);
|
|
// 设置队列容量
|
|
executor.setQueueCapacity(100);
|
|
// 设置线程活跃时间(秒)
|
|
executor.setKeepAliveSeconds(60);
|
|
executor.setThreadNamePrefix("DELETEWebhook_Async-Service-");
|
|
// 设置拒绝策略
|
|
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
|
executor.initialize();
|
|
return executor;
|
|
}
|
|
|
|
@Bean("updateWebhookTaskExecutor")
|
|
public Executor updateWebhookTaskExecutor() {
|
|
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
|
executor.setCorePoolSize(5);
|
|
executor.setMaxPoolSize(10);
|
|
// 设置队列容量
|
|
executor.setQueueCapacity(100);
|
|
// 设置线程活跃时间(秒)
|
|
executor.setKeepAliveSeconds(60);
|
|
executor.setThreadNamePrefix("UpdateWebhook_Async-Service-");
|
|
// 设置拒绝策略
|
|
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
|
executor.initialize();
|
|
return executor;
|
|
}
|
|
}
|