Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

37.7. 自定义线程池 ThreadPoolExecutor

自定义线程池

37.7.1. ThreadPoolExecutor

			
    @Bean("queueThreadPool")
    public ThreadPoolExecutor queueThreadPool() {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
                5,
                10,
                60,
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(10),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
        return threadPoolExecutor;
    }
			
			

37.7.2. 注入自定义线程池bean

		
	 // 注入自定义线程池bean
    @Autowired
    private ThreadPoolExecutor threadPoolExecutor;
    
    threadPoolExecutor.execute(new Runnable() {
        @Override
        public void run() {
            System.out.println("=======");

        }
    });