0

我遇到了一个问题,tomcat 在不时请求时没有停止,我必须手动终止该进程。我使用的是标准弹簧堆栈(JPA,MVC)。这并不总是发生,只有大约 70% 的时间。我在 Windows、OSX 和 Linux 平台上都看到过这种情况……

任何想法为什么会发生这种情况.. 在下面的日志中,您将看到 2 个 SERVERE 日志条目,但从这个问题:为了防止内存泄漏,JDBC 驱动程序已被强制注销似乎说这不是 Tomcat 的问题所以它留下了软参考..

任何想法为什么这可以阻止tomcat关闭?

编辑:关于进一步的建议和分析 - 看起来 apache HTTP 客户端正在使用 DateUtils 类,该类又创建一个 ThreadLocal 实例。我们的代码使用 HTTP 客户端对外部服务进行分类......当然这应该是一个非常如果它驻留在 Apache HTTP 客户端中的常见问题,因为使用它来调用外部 HTTP 端点并不少见?

日志输出下方的线程转储

谢谢,

伊恩。

-2013-01-04 09:18:33,189 DEBUG [http-bio-9999-exec-8] view.InternalResourceView (InternalResourceView.java:236) - Forwarding to resource [/WEB-INF/views/auth/login.jsp] in InternalResourceView 'auth/login'
2013-01-04 09:18:33,191 DEBUG [http-bio-9999-exec-8] servlet.FrameworkServlet (FrameworkServlet.java:913) - Successfully completed request
Jan 04, 2013 9:18:33 AM org.apache.catalina.core.StandardServer await
INFO: A valid shutdown command was received via the shutdown port. Stopping the Server instance.
Jan 04, 2013 9:18:33 AM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["http-bio-9999"]
Jan 04, 2013 9:18:33 AM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["ajp-bio-8009"]
Jan 04, 2013 9:18:33 AM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Catalina
2013-01-04 09:18:33,409 INFO  [localhost-startStop-2] support.AbstractApplicationContext (AbstractApplicationContext.java:1025) - Closing WebApplicationContext for namespace 'test-servlet': startup date [Thu Jan 03 17:56:22 GMT 2013]; parent: Root WebApplicationContext
2013-01-04 09:18:33,409 DEBUG [localhost-startStop-2] support.AbstractBeanFactory (AbstractBeanFactory.java:245) - Returning cached instance of singleton bean 'org.springframework.context.annotation.internalScheduledAnnotationProcessor'
2013-01-04 09:18:33,410 DEBUG [localhost-startStop-2] support.AbstractBeanFactory (AbstractBeanFactory.java:245) - Returning cached instance of singleton bean 'lifecycleProcessor'
2013-01-04 09:18:33,410 INFO  [localhost-startStop-2] support.DefaultSingletonBeanRegistry (DefaultSingletonBeanRegistry.java:433) - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@37f293d3: defining beans []; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@2f701b4e
log4j:WARN No appenders could be found for logger (org.springframework.web.context.support.AnnotationConfigWebApplicationContext).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Jan 04, 2013 9:18:33 AM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: The web application [] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Jan 04, 2013 9:18:33 AM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [] created a ThreadLocal with key of type [org.apache.http.impl.cookie.DateUtils$DateFormatHolder$1] (value [org.apache.http.impl.cookie.DateUtils$DateFormatHolder$1@3f94bcde]) and a value of type [java.lang.ref.SoftReference] (value [java.lang.ref.SoftReference@3dfbb36e]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Jan 04, 2013 9:18:33 AM org.apache.coyote.AbstractProtocol stop
INFO: Stopping ProtocolHandler ["http-bio-9999"]
Jan 04, 2013 9:18:33 AM org.apache.coyote.AbstractProtocol stop
INFO: Stopping ProtocolHandler ["ajp-bio-8009"]
Jan 04, 2013 9:18:33 AM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["http-bio-9999"]
Jan 04, 2013 9:18:33 AM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["ajp-bio-8009"]

--线程转储-----

在 org.apache.http.impl.cookie.DateUtils$DateFormatHolder$1.initialValue(DateUtils.java:220) 在 org.apache.http.impl.cookie.DateUtils$DateFormatHolder$1.initialValue(DateUtils.java:219) 在 java .lang.ThreadLocal.setInitialValue(ThreadLocal.java:160)
at java.lang.ThreadLocal.get(ThreadLocal.java:150) at org.apache.http.impl.cookie.DateUtils$DateFormatHolder.formatFor(DateUtils.java:239 ) 在 org.apache.http.impl.cookie.DateUtils.parseDate(DateUtils.java:156)
在 org.apache.http.impl.cookie.DateUtils.parseDate(DateUtils.java:114) 在 org.apache.http.impl.cookie.BasicExpiresHandler.parse(BasicExpiresHandler.java:61) 在 org.apache.http.impl .cookie.CookieSpecBase.parse(CookieSpecBase.java:93) 在 org.apache.http.impl.cookie.BestMatchSpec.parse(BestMatchSpec.java:135) 在 org.apache.http.client.protocol.ResponseProcessCookies.processCookies(ResponseProcessCookies .java:114) 在 org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:116) 在 org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:116) 在 org.apache.http.client.protocol.ResponseProcessCookies.process(ResponseProcessCookies.java:95)。 http.protocol.HttpRequestExecutor.postProcess(HttpRequestExecutor.java:342) 在 org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:462) 在 org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754) 在 org.apache.http .impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)

4

1 回答 1

0

It seems that your code uses [org.apache.http.impl.cookie.DateUtils$DateFormatHolder$] at some point. This old question tells that HttpClient may be issueing the reference.

So you need to look for code, that is using HttpClient - and be sure to cleanup any Thread or HttpClient related resources on contextDestroy.

Look at threads in your application, that use HttpClient, you should verify that these threads get stopped properly on shutdown.

于 2013-01-04T14:31:18.290 回答