A, 서비스 계층
com.uos.schedule.service 패키지;
수입 org.springframework.scheduling.annotation.Async;
수입 org.springframework.stereotype.Service;
/ **
* 서비스 레이어
* /
@서비스
공용 클래스 OwnAsynService {
@Async
공공 무효 sendSMS () 예외 : InterruptedException를 {던졌습니다
에서 System.out.println ( "SMS 인증 서비스 호출 방법");
긴 startTime을 =에 System.currentTimeMillis ();
Thread.sleep를 (5000);
긴 endTime- 사용자 =에 System.currentTimeMillis ();
에서 System.out.println는 ( "SMS 서비스 실행 완료 시간이 소요 : \ t"+ (endTime- 사용자 - startTime을));
}
}
OwnAsynService
둘째, 컨트롤러 레이어
com.uos.schedule.controller 패키지;
수입 com.uos.schedule.service.OwnAsynService;
수입 org.springframework.beans.factory.annotation.Autowired;
수입 org.springframework.web.bind.annotation.GetMapping;
수입 org.springframework.web.bind.annotation.RestController;
/ **
* 제어 계층
* /
@RestController
public class OwnAsyncController {
@Autowired
private OwnAsynService ownAsynService;
@GetMapping(value = {"sendSMS"})
public String sendSMS() throws InterruptedException {
Long startTime = System.currentTimeMillis();
ownAsynService.sendSMS();
Long endTime = System.currentTimeMillis();
System.out.println("主业务执行消耗完成时间:\t" + (endTime - startTime));
return "success";
}
}
OwnAsyncController
三、主程序类
四、结果测试