Spring Boot异步任务

Spring Boot异步任务,必须在Application配置以下信息。

1. @EnableAsync

2. 注册名为taskExecutor的Bean:

@Bean(name="taskExecutor")

    public TaskExecutor workExecutor() {

        ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();

        threadPoolTaskExecutor.setThreadNamePrefix("Async-");

        threadPoolTaskExecutor.setCorePoolSize(3);

        threadPoolTaskExecutor.setMaxPoolSize(3);

        threadPoolTaskExecutor.setQueueCapacity(600);

        threadPoolTaskExecutor.afterPropertiesSet();

        logger.info("ThreadPoolTaskExecutor set");

        return threadPoolTaskExecutor;

    }

你可能感兴趣的:(Spring Boot异步任务)