Runnable
인터페이스를 구현하는 클래스 MyRunnable
이 있습니다. 이 클래스는 다음과 같이 메인 스레드에서 통해 인스턴스된다Runnable의 인터럽트는 다른 스레드도 인터럽트합니까?
MyRunnable myRunnable = new MyRunnable();
Thread thread = new Thread(myRunnable);
thread.start();
MyRunnable
스레드를 멈추는 stop()
방법을 구현하고 또한 현재 스레드에서 interrupt()
를 호출 스레드가 어떤 원인 중단, 그러나
public void stop()
{
LOG.info("Stopping");
this.runService = false; // reset running flag in order to stop the while-loop
Thread.currentThread().interrupt(); // interrupt any blocking operations
}
내가 이해할 수없는 주요한 문제들. 나는이 스레드뿐만 아니라 모든 다른 스레드뿐만 아니라 메인 스레드를 포함하여 중단 것으로 나타났습니다! 이 데이터베이스 연결이 깨진 아무 것도이 스레드와 함께 할 등. 내가 인터럽트 호출을 제거하면 모든 것이 예상대로 작동합니다.
나는/시작/Runnable 중지 꽤 간단하지만 어쩌면 내가 뭔가 잘못하고 있다고 생각 했나요?
어떤 스레드에서'stop()'메서드를 호출하고 있습니까? –
메인 스레드에서. –
'interrupt()'는 이전에 만든 스레드가 아니라 하나의 스레드를 인터럽트합니다. –