TheadPoolTaskExecutorConfiguration.java
1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.topdraw.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* @author :
* @description:
* @function :
* @date :Created in 2022/6/22 11:06
* @version: :
* @modified By:
* @since : modified in 2022/6/22 11:06
*/
@Configuration
public class TheadPoolTaskExecutorConfiguration {
@Value("${task.pool.core-pool-size:16}")
private Integer corePoolSize;
@Value("${task.pool.core-pool-size:35}")
private Integer maxPoolSize;
@Value("${task.pool.keep-alive-seconds:10}")
private Integer keepAliveSeconds;
@Value("${task.pool.queue-capacity:300}")
private Integer queueCapacity;
@Bean
@Primary
public ThreadPoolTaskExecutor getThreadPoolTaskExecutor() {
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
threadPoolTaskExecutor.setCorePoolSize(corePoolSize);
threadPoolTaskExecutor.setMaxPoolSize(maxPoolSize);
threadPoolTaskExecutor.setKeepAliveSeconds(keepAliveSeconds);
threadPoolTaskExecutor.setQueueCapacity(queueCapacity);
threadPoolTaskExecutor.setWaitForTasksToCompleteOnShutdown(true);
threadPoolTaskExecutor.initialize();
return threadPoolTaskExecutor;
}
/*@Bean
public ThreadPoolExecutor getThreadPoolTaskExecutor() {
ArrayBlockingQueue arrayBlockingQueue = new ArrayBlockingQueue(queueCapacity);
ThreadPoolExecutor threadPoolTaskExecutor = new ThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveSeconds, TimeUnit.SECONDS, arrayBlockingQueue);
return threadPoolTaskExecutor;
}*/
}