출처 http://stackoverflow.com/questions/1087475/when-does-javas-thread-sleep-throw-interruptedexception
종종 스레드를 종료하다 발쌩하는 예외인데 유용하다.
If you use it in a single threaded app (and also in some multi-threaded apps), that method will never be triggered. Ignoring it by having an empty catch clause i would not recommend. The throwing of the InterruptedException clears the interrupted state of the Thread, so if not handled properly that info gets lost. Therefore i would propose to run:
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
// code for stopping current task so thread stops
}
Which sets that state again. After that, finish execution. This would be correct behaviour, even tough never used.
What might be better is to add a:
} catch (InterruptedException e) {
assert false;
}
statement to the catch block. That basically means that it must never happen. So if the code is re-used in an environment where it might happen it will complain about it.
'개발 공부 기록하기 > - Kotlin & Java' 카테고리의 다른 글
[Java-lib] Object Mapper에 대해서 (0) | 2016.03.08 |
---|---|
Callable과 Thread (0) | 2016.02.04 |
[Java] 디렉토리내 일정기간 지난 파일 삭제 (0) | 2016.01.05 |
ScheduleExecutorService 와 Timer를 이용한 일정시간 메소드 실행 (0) | 2016.01.04 |
BufferedReader 에 String값 넣기 (1) | 2015.12.14 |