我正在使用ScheduledExecutorService
来运行预定线程。
我实施了ServletContextListener.contextDestroyed
并且调用了ScheduledExecutorService.shutdownNow
和awaitTermination
。Tomcat 7和ScheduledExecutorService.shutdown
下面是一个例子:
重度::
@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(); } }
尽管如此,我从Tomcat 7得到以下错误Web应用[/ servlet的]似乎已经开始了 线程名称为[Timer-0]但无法停止它。这很可能是 创建内存泄漏。
该日志可以忽略吗?或者我做错了什么?
感谢
我的意思是,我的想法是:你的清理责任在哪里停止?还有什么可以做的呢?用消防水带打开箱子? 非常认真,我的意思是说,它看起来像你正在做的一切你能做的......我会忽略这个错误。 – ControlAltDel 2012-03-29 17:51:41
你可以参考我以前的文章:) http://stackoverflow.com/questions/9926356/scheduledexecutorservice-when-shutdown-should-be-invoked – lili 2012-03-30 13:07:20