2

I'm getting this error:

SEVERE: The web application [/app] appears to have started a thread named [ImmediateThread-1469817702874] but has failed to stop it. This is very likely to create a memory leak.

I am using Jersey for this and I believe it creates the ImmediateThread and basically, I have no control over this. Is there any way where I can just access all ThreadLocal objects and remove them on contextDestroyed()?

I understand that this can be ignored if we just basically restart the Tomcat server but I would love to have the privilege to just undeploy and deploy apps without worrying about possible memory leaks.

I'm using Java 7, Tomcat 7, Jersey, Hibernate.

mpmp
  • 2,409
  • 4
  • 33
  • 46
  • see http://stackoverflow.com/questions/29269277/how-to-identify-and-remove-threads-threadlocals-initiated-from-our-webapp-in-jav?rq=1 –  Jul 29 '16 at 18:56
  • See [JERSEY-2979 - ImmediateThread memory leak](https://java.net/jira/browse/JERSEY-2979). – Andreas Jul 29 '16 at 19:15

1 Answers1

0

If you used new enough HK2, you should be able to have tools to control the Immediate threads as John Wells is suggesting (see https://java.net/jira/browse/HK2-280?focusedCommentId=390557&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-390557).

Actually, if the tools were good enough it would be cool if we enabled the Immediate scope by default in Jersey as it was intended (see https://java.net/jira/browse/JERSEY-2979).
I suppose, the idea would be to use Jersey controlled executor service for Immediate threads which gets shutdown in the right moments of Jersey Application lifecycle (e.g., by using https://jersey.java.net/apidocs/latest/jersey/org/glassfish/jersey/server/spi/ContainerLifecycleListener.html).

It would be cool if you were able to contribute to this ticket https://java.net/jira/browse/JERSEY-2979 (at least by adding an example).

Stepan Vavra
  • 3,884
  • 5
  • 29
  • 40