本文共 1191 字,大约阅读时间需要 3 分钟。
ThreadPoolConfig
package com.newland.iot.config;import org.springframework.beans.factory.annotation.Value;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.core.task.TaskExecutor;import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;@Configurationpublic class ThreadPoolConfig { @Value("${spring.executor.core.pool.size:500}") private Integer corePoolSize; @Value("${spring.executor.max.pool.size:0x7fffffff}") private Integer maxPoolSize; @Value("${spring.executor.queue.capacity:0x7fffffff}") private Integer queueCapacity; @Bean public TaskExecutor taskExecutor() { ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); taskExecutor.setCorePoolSize(corePoolSize); taskExecutor.setMaxPoolSize(maxPoolSize); taskExecutor.setQueueCapacity(queueCapacity); taskExecutor.setWaitForTasksToCompleteOnShutdown(true); return taskExecutor; }}
使用
@Componentpublic class TestTaskExecutor { @Autowired private TaskExecutor taskExecutor; taskExecutor.execute(() -> System.out.println("taskExecutor..."));}
转载地址:http://vpsjn.baihongyu.com/