Spring Boot异步线程

1、添加注解

1
2
3
4
5
6
7
@EnableAsync
public class TestApplication {
 
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}
}

2、添加配置文件

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
package test.config;
 
import java.util.concurrent.Executor;
 
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 
@Configuration
public class AsyncTaskExecutor {
 
    @Bean(name = "threadPoolTaskExecutor")
    public Executor threadPoolTaskExecutor() {
        return new ThreadPoolTaskExecutor();
    }
}

发表评论

欢迎阅读『Spring Boot异步线程|Java、开发语言、框架算法|Nick Tan-梓潼Blog』