Michele Mariotti
Michele Mariotti

Reputation: 7469

tomcat 7.0 and jax-ws 2.2.5 memory leak

i'm building a ws with tomcat and jax-ws. when i stop my application, generally while redeploying from eclipse, i get this message:

25-mar-2012 16.21.16 com.sun.xml.ws.transport.http.servlet.WSServletDelegate destroy
INFO: WSSERVLET15: JAX-WS servlet destroyed
25-mar-2012 16.21.16 com.sun.xml.ws.transport.http.servlet.WSServletContextListener contextDestroyed
INFO: WSSERVLET13: JAX-WS context listener destroyed
25-mar-2012 16.21.16 org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
GRAVE: The web application [/xccm] created a ThreadLocal with key of type [com.sun.xml.ws.api.streaming.XMLStreamReaderFactory$Default$1] (value [com.sun.xml.ws.api.streaming.XMLStreamReaderFactory$Default$1@7edeaa13]) and a value of type [com.sun.xml.internal.stream.XMLInputFactoryImpl] (value [com.sun.xml.internal.stream.XMLInputFactoryImpl@4c700677]) 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. 

diggin with ClasspathHelper i found that com.sun.xml.ws.api.streaming.XMLStreamReaderFactory$Default$1 is referenced by jaxws-rt.jar

however i do not explicitly use any jax-ws class in my code except:

import javax.jws.WebParam;
import javax.jws.WebService;
import javax.xml.bind.JAXBContext;

and as far as i know tomcat loads com.sun.xml.ws.transport.http.servlet.WSServlet (and the other classes in log snippet).

any idea how to solve this issue?

thx

Upvotes: 3

Views: 6312

Answers (1)

Ingo Kegel
Ingo Kegel

Reputation: 48105

A library you use (the JAX-WS implementation) has created a thread local whose key is of a type that has been loaded by your web app class loader.

This means that the web app class loader cannot be garbage collected because a class loader can only be garbage collected if no instances of its classes are strongly referenced. After multiple re-deployments, your JVM will run out of perm gen space.

A real fix would be to listen for the life cycle of your web application and remove the thread local when it is shut down. However, since you don't know the internals of the JAX-WS implementation, it will be difficult for you to do this.

Another solution would be to add jaxws-rt.jar (and maybe other JAR files related to JAX-WS) to the "lib" directory of your Tomcat installation. In that case, they will be loaded by the common class loader and will not be reloaded when you re-deploy your web application.

Upvotes: 3

Related Questions