12345678910111213141516171819202122232425262728 |
- package thyyxxk.webserver.config;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.core.task.TaskExecutor;
- import org.springframework.scheduling.annotation.EnableAsync;
- import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
- import java.util.concurrent.ThreadPoolExecutor;
- @Configuration
- @EnableAsync
- public class TaskConfig {
- @Bean
- public TaskExecutor taskExecutor() {
- ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
- executor.setCorePoolSize(8);
- executor.setMaxPoolSize(16);
- executor.setQueueCapacity(50);
- executor.setKeepAliveSeconds(120);
- executor.setThreadNamePrefix("web-server-async-");
- executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
- executor.setWaitForTasksToCompleteOnShutdown(true);
- return executor;
- }
- }
|