CompletableFuture.supplyAsync(
() -> {
transporter.write(req);
//here take the value from a blocking queue,will throw a interruptedException
return responseQueue.take();
}, executorService);
interruptedException을 처리하는 일반적인 방법은 다시 인터럽트하거나 interruptedException을 throw하는 것이지만 둘 다 작동하지 않습니다. 누구나 아이디어가 있으십니까?JDK8 CompletableFuture.supplyAsync interruptedException을 처리하는 방법
"*하지만 둘 다 작동하지 않습니다." "=> 왜? – assylias
모두 컴파일러 오류가 있습니다. 직접 throw 예외가 발생하면 컴파일러는 처리되지 않은 예외를 표시하고 catch하고 Thead.current.interrupt를 호출하면 컴파일러에서 T 유형을 반환해야합니다. – GrapeBaBa
예. 돌아 오거나 던지십시오. 널 (null)을 리턴하기로 결정한 경우, 다음과 같습니다.'try {return queue.take(); } catch (InterruptedException e) {Thread.currentThread(). interrupt(); null를 돌려 준다. }' – assylias