wvp-GB28181-pro/src/main/java/com/genersoft/iot/vmp/conf/ThreadPoolTaskConfig.java

58 lines
2.1 KiB
Java
Raw Normal View History

package com.genersoft.iot.vmp.conf;
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.ThreadPoolExecutor;
@Configuration
2021-11-17 17:01:59 +08:00
@EnableAsync(proxyTargetClass = true)
public class ThreadPoolTaskConfig {
/**
* 线线线0线
* 线线corePoolSize
* 线线maxPoolSize使
*/
/**
* 线线
*/
private static final int corePoolSize = 5;
/**
* 线
*/
private static final int maxPoolSize = 30;
/**
* 线
*/
private static final int keepAliveTime = 30;
/**
*
*/
private static final int queueCapacity = 10000;
/**
* 线
*/
2021-11-17 17:01:59 +08:00
private static final String threadNamePrefix = "wvp-sip-handle-";
@Bean("taskExecutor") // bean的名称默认为首字母小写的方法名
public ThreadPoolTaskExecutor taskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(corePoolSize);
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
executor.setKeepAliveSeconds(keepAliveTime);
executor.setThreadNamePrefix(threadNamePrefix);
// 线程池对拒绝任务的处理策略
// CallerRunsPolicy由调用线程提交任务的线程处理该任务
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// 初始化
executor.initialize();
return executor;
}
}