1
스프링 MVC (Controller + Service + ThreadPoolTaskExecutor), Callable 및 Future. 내가 가진자바 멀티 스레드 스레드를 중지하고 실행 프로그램을 해제하는 방법은 무엇입니까?
@Controller
launch-method [invokes Service:launch-method and get result with Future]
stop-method [invokes Service:stop-method]
@Service [to launch async Tasks]
launch-method [Loop with threadPoolTaskExecutor.submit(callable)]
stop-method [threadPoolTaskExecutor.shutdown()]
정지 이벤트 흐름은 다음과 같습니다
- 사용자가 정지 버튼을 클릭하고 컨트롤러 호출 : 중지-방법는
- 컨트롤러 : 중지-방법이를 호출을 서비스 : stop-method
- ¿? 서비스 : 종료 방법을-중지하고 컨트롤러 통지 : 출시-방법
을 그리고 나는 컨트롤러에 통보, 3 단계를 코딩해야합니다 출시-방법 프로세스가 완료되었음을.
threadPoolTaskExecutor.shutdown()가 컨트롤러 해제하지 않는 이유를 모르겠어요 : 출시-방법에 대기 (=하는 Future.get 결과) 예외가 발생하지 않습니다.
try {
for (Future<String> future : sentResult) {
result = future.get();
...
}
} catch (ExecutionException e) {...}
catch (InterruptedException e) {...}
catch (CancellationException e) {...}
catch (Exception e) {...}
의견이 있으십니까?
감사합니다. 그러나 Controller와 Service 간의 통신은 Service 메소드의 결과를 기다리고있는 Future 객체로 설정됩니다. –