springBoot中的異步和定時任務

具體的操做步驟就不寫啦java

AsyncService.javaapp

Serviceasync

public class AsyncService {測試

[@Async](https://my.oschina.net/553709938)

public void hello(){this

try {
  
      Thread.sleep(10000);
	  
  }catch (InterruptedException e){
  
      e.printStackTrace();
	  
  }
  System.out.println("數據處理中");

} } 測試 @RestController.net

public class AsyController {code

@Autowiredblog

AsyncService asyncService;

@GetMapping("/hello")get

public String hello(){

asyncService.hello();

return  "success";

} }io

@Service

public class scheduleService {

//,表枚舉
//-表區間
//* 表任意
//? 表衝突匹配
// /41 表步長

@Scheduled(cron = "0,1,2,3,5,6 * * * * *")

public void hello(){

System.out.println("hello this is cron schedule");

} }

相關文章
相關標籤/搜索