修改线程池配置
This commit is contained in:
@@ -1,17 +1,40 @@
|
|||||||
package com.volvo.ai.analytic.center.config;
|
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.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class ExecutorConfig {
|
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")
|
@Bean("corpusProcessExecutor")
|
||||||
public ExecutorService corpusProcessExecutor() {
|
public ThreadPoolTaskExecutor corpusProcessExecutor() {
|
||||||
int poolSize = Runtime.getRuntime().availableProcessors() + 2;
|
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||||
return Executors.newFixedThreadPool(poolSize);
|
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