启动类开启异步功能
@EnableAsync
@SpringBootApplication
public class AsynApplication {
public static void main(String[] args) {
SpringApplication.run(AsynApplication.class, args);
}
}
在需要使用异步的类或者方法开启
@Service
public class
AsynService {
@Async
public void asyn(){
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("222222");
}
}