1. 異步任務(wù)
// SpringBoot 入口加
@EnableAsync // 開(kāi)啟異步注解
@RestController
public class AsyncController{
@Autowired
AsyncService asyncService;
@GetMapping("hello")
public String hello(){
asyncService.hello();
return "success";
}
}
@service
public class AsyncService{
@Async // 告訴 spring 這是一個(gè)異步方法
public void hello(){
try{
Thread.sleep();
}catch(Exception ex){
}
}
}