2012-03-29 2 views
5

내가 예약 된 스레드를 실행하는 데 ScheduledExecutorService을 사용하고 있습니다.
나는 ServletContextListener.contextDestroyed을 구현 ScheduledExecutorService.shutdownNowawaitTermination를 호출. 여기 톰캣 7 ScheduledExecutorService.shutdown

은 예입니다

SEVERE : : 아직도

@Override 
public void contextDestroyed(ServletContextEvent servletcontextevent) { 
    pool.shutdownNow(); // Disable new tasks from being submitted 
    try { 
     // Wait a while for existing tasks to terminate 
     if (!pool.awaitTermination(50, TimeUnit.SECONDS)) { 
     pool.shutdownNow(); // Cancel currently executing tasks 
     System.err.println("Pool did not terminate"); 
     } 
    } catch (InterruptedException ie) { 
     // (Re-)Cancel if current thread also interrupted 
     pool.shutdownNow(); 
     // Preserve interrupt status 
     Thread.currentThread().interrupt(); 
    }   
} 


, 내가 톰캣 7에서 다음과 같은 오류가 발생하고 웹 응용 프로그램 [/ 서블릿은]을 시작했습니다 보인다 [Timer-0]이라는 스레드가 스레드를 중지하지 못했습니다. 메모리 누수가 발생할 가능성이 높습니다 ( ).

이 로그는 무시 할 수 있습니까? 아니면 내가 잘못하고있는거야?

감사

+0

제 생각은 정리를하기위한 당신의 책임은 어디에서 멈 춥니 까? 그 밖의 무엇이 여기에서 끝날 수 있습니까? 소방 호스로 상자에 닿았나요? 모든 진지함을 말하자면, 당신이 할 수있는 모든 일을하는 것처럼 보입니다 ... 나는 그 오류를 무시할 것입니다. – ControlAltDel

+0

내 이전 게시물을 참조 할 수 있습니다 :) http://stackoverflow.com/questions/9926356/scheduledexecutorservice-when-shutdown-should-be-invoked – lili

답변

4

이 오류는 스레드 풀과 관련이 있습니까? 스레드 이름 'Timer-0'으로 판단하면 아마 일종의 타이머에 의해 시작되었을 것입니다.

또한, 당신은 (는) 당신이 아직 종료 (JavaDoc을 참조) 기다리고 작업의 목록을 반환해야 shutdownNow의. 목록이 비어 있지 않으면 더 기다릴 논리를 만들 수 있습니다.

1

당신은 제대로 ScheduledExecutorService를 종료한다. 그러나 기본적으로 ExecutorService으로 생성 된 스레드는 pool-X-thread-Y이라는 이름 지정 규칙을 따릅니다.

Timer-0 스레드 Timer 클래스에 의해 생성됩니다. 코드와 라이브러리에서 찾아보십시오.