39 lines
1.1 KiB
Java
39 lines
1.1 KiB
Java
package com.gzzn.omms.msgexchangeapi.config;
|
|||
|
|
|
||
|
|
import java.util.concurrent.Executor;
|
||
|
|
|
||
|
|
import org.springframework.beans.factory.annotation.Value;
|
||
|
|
import org.springframework.context.annotation.Bean;
|
||
|
|
import org.springframework.context.annotation.Configuration;
|
||
|
|
import org.springframework.scheduling.annotation.EnableAsync;
|
||
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 定时器多线程配置
|
||
|
|
* @author fhc
|
||
|
|
*
|
||
|
|
*/
|
||
|
|
@Configuration
|
||
|
|
@EnableAsync
|
||
|
|
public class ScheduledAsyncConfig {
|
||
|
|
|
||
|
|
/*
|
||
|
|
此处成员变量应该使用@Value从配置中读取
|
||
|
|
*/
|
||
|
|
@Value("${scheduled.corePoolSize}")
|
||
|
|
private int corePoolSize;
|
||
|
|
@Value("${scheduled.maxPoolSize}")
|
||
|
|
private int maxPoolSize;
|
||
|
|
@Value("${scheduled.queueCapacity}")
|
||
|
|
private int queueCapacity;
|
||
|
|
@Bean
|
||
|
|
public Executor taskExecutor() {
|
||
|
|
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||
|
|
executor.setCorePoolSize(corePoolSize);
|
||
|
|
executor.setMaxPoolSize(maxPoolSize);
|
||
|
|
executor.setQueueCapacity(queueCapacity);
|
||
|
|
executor.initialize();
|
||
|
|
return executor;
|
||
|
|
}
|
||
|
|
}
|