修改线程池配置
This commit is contained in:
@@ -1,17 +1,40 @@
|
||||
package com.volvo.ai.analytic.center.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.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
@Configuration
|
||||
public class ExecutorConfig {
|
||||
|
||||
@Value("${task.pool.corePoolSize}")
|
||||
private int corePoolSize;
|
||||
|
||||
@Value("${task.pool.maxPoolSize}")
|
||||
private int maxPoolSize;
|
||||
|
||||
@Value("${task.pool.keepAliveSeconds}")
|
||||
private int keepAliveSeconds;
|
||||
|
||||
@Value("${task.pool.queueCapacity}")
|
||||
private int queueCapacity;
|
||||
|
||||
@Bean("corpusProcessExecutor")
|
||||
public ExecutorService corpusProcessExecutor() {
|
||||
int poolSize = Runtime.getRuntime().availableProcessors() + 2;
|
||||
return Executors.newFixedThreadPool(poolSize);
|
||||
public ThreadPoolTaskExecutor corpusProcessExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
int corePoolSize = Runtime.getRuntime().availableProcessors() + 2;
|
||||
|
||||
executor.setCorePoolSize(corePoolSize);
|
||||
executor.setMaxPoolSize(maxPoolSize);
|
||||
executor.setQueueCapacity(queueCapacity);
|
||||
executor.setThreadNamePrefix("corpus-process-pool-");
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
executor.setKeepAliveSeconds(keepAliveSeconds);
|
||||
executor.initialize();
|
||||
|
||||
return executor;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user