自动化立体仓库 - WMS系统
zc
2024-11-01 797fce4ad48f7b70dc08766068b64f35ee9d4775
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
package com.zy.common.config;
 
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;
 
/**
 * Created by vincent on 2022/5/21
 */
@Configuration
@EnableAsync
public class ThreadPoolConfig {
 
    @Bean(name = "orderThreadPool")
    public ThreadPoolTaskExecutor orderThreadPool() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        int core = Runtime.getRuntime().availableProcessors();
        core = 2;
        //设置核心线程数
        executor.setCorePoolSize(core);
        //设置最大线程数
        executor.setMaxPoolSize(core * 10 + core);
        //除核心线程外的线程存活时间
        executor.setKeepAliveSeconds(3);
        //缓冲队列
        executor.setQueueCapacity(core);
        executor.setThreadNamePrefix("order-task-");
        //设置拒绝策略
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        return executor;
    }
 
 
}