@Async开启异步调用,"simpleExecutor"代表要使用的线程池
@Component
public class AsyncTest {
@Async("simpleExecutor")
public void test1() {
System.out.println("异步执行test1!!!");
System.out.println("线程id:" + Thread.currentThread().getId());
System.out.println("线程名称:" + Thread.currentThread().getName());
}
@Async("commonExecutor")
public void test2() {
System.out.println("异步执行test2!!!");
System.out.println("线程id:" + Thread.currentThread().getId());
System.out.println("线程名称:" + Thread.currentThread().getName());
}
}
@EnableAsync 开启async功能,并扫描当前范围的配置