티스토리 뷰

interrupt() 메서드를 호출하여 스레드를 중지시킬려고 할 때 항상 해당 스레드가 멈추는 것은 아니다. API에 있는 Thread 클래스의 interrupt() 메서드에는 다음과 같은 설명이 있다.

public void interrupt()

Interrupts this thread.

Unless the current thread is interrupting itself, which is always permitted, the checkAccess method of this thread is invoked, which may cause a SecurityException to be thrown.

If this thread is blocked in an invocation of the wait(), wait(long), or wait(long, int) methods of the Object class, or of the join(), join(long), join(long, int), sleep(long), or sleep(long, int), methods of this class, then its interrupt status will be cleared and it will receive an InterruptedException.

If this thread is blocked in an I/O operation upon an InterruptibleChannel then the channel will be closed, the thread's interrupt status will be set, and the thread will receive a ClosedByInterruptException.

If this thread is blocked in a Selector then the thread's interrupt status will be set and it will return immediately from the selection operation, possibly with a non-zero value, just as if the selector's wakeup method were invoked.

If none of the previous conditions hold then this thread's interrupt status will be set.

Interrupting a thread that is not alive need not have any effect.

간단하게 설명하면 interrput() 메서드는 해당 스레드가 'block' 되거나 특정 상태에서만 작동한다는 말이다. interrupt() 메서드는 절대적인 것이 아니다.

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
링크
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
글 보관함