cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mauro Molinari (JIRA)" <>
Subject [jira] Commented: (CXF-2164) CXFBusImpl never removed from ThreadLocal, generates permgen out of memory error after some redeployments
Date Wed, 08 Sep 2010 16:22:34 GMT


Mauro Molinari commented on CXF-2164:

I must correct myself. As the original reporter said, the call to shutdown does not resolve
the problem, because I just saw that it does not unset the ThreadLocal, but simply sets to
null an internal property (defaultBus).

The bad news is that I just realized that the shutdown sequence can actually be made on a
different thread: that is, the context may be created in thread "main", but destroyed in thread
htttp-8080-1 (the one that serves my request to stop the web application in the Tomcat Manager

So, I don't see any straight way to fix this problem without thinking about the reason of
that ThreadLocal. Maybe the method org.apache.cxf.BusFactory.setDefaultBus(Bus) should at
least let the user specify whether the TheadLocal localBus property should also be set together
with the defaultBus property. After that, maybe the constructor of CXFBusImpl should set only
the default bus property, not the localBus one.


> CXFBusImpl never removed from ThreadLocal, generates permgen out of memory error after
some redeployments
> ---------------------------------------------------------------------------------------------------------
>                 Key: CXF-2164
>                 URL:
>             Project: CXF
>          Issue Type: Bug
>          Components: Bus
>    Affects Versions: 2.1.4
>            Reporter: Francois Masurel
>            Assignee: Bharath Ganesh
>             Fix For: 2.2.2
>         Attachments: cxf_threadlocal.jpg,, threadlocal.patch
> I've found this message on a mailing list recently, and it doesn't seem to have been
resolved as we have the same problem with version 2.1.4 of CXF on one of our webapp :
> Hello CXF users,
> I've been  working on figuring out why our JBoss servers keep going down with permgen
> of memory exceptions when we redeploy our war files. To do this I had been using a profiler
> to inspect the WebAppClassloader to find out what was keeping it from being garbage collected.
> One such culprit was the class org.apache.cxf.BusFactory
> The BusFactory has a ThreadLocal in which it stores a copy of CXFBusImpl. However, this
> getting cleaned up properly when the war is undeployed. I noticed that CXFBusImpl has
a shutdown
> method that calls BusFactory.setDefaultBus(null) which in turn sets the value stored
in the
> ThreadLocal to null. However, this doesn't seem to be getting called.
> The way we are using CXF from spring is with the following WEB-INF/services.xml file
in our
> war:
>   <beans xmlns="" xmlns:xsi=""
>     xmlns:amq="" xmlns:jaxws=""
>     xmlns:http-conf=""
>     xsi:schemaLocation="
>     default-autowire="byType">
>     <import resource="classpath:META-INF/cxf/cxf.xml" />
>     <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
>     <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
>     <jaxws:endpoint id="helloService" implementor="#helloSvc" address="/HelloService"
>   </beans>
> I'm not really sure why this Bus.shutdown() isn't getting called or even who is responsible
> for calling it. I tried doing something along the lines of:
>   WebApplicationContext webContext = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
>   if (webContext.containsBean("cxf")) {
>     CXFBusImpl cxfBus = (CXFBusImpl) webContext.getBean("cxf");
>     cxfBus.shutdown(true);
>   }
> But that didn't work. What I eventually ended up doing was to have the following hack
in the
> shutdown sequence of our webapp:
>   Field field = org.apache.cxf.BussFactory.class.getDeclaredField("localBus");
>   field.setAccessible(true);
>   ThreadLocal<?> localBus = (ThreadLocal<?>) field.get(null);
>   localBus.remove();
> This did work but obviously it is a bit of an ugly hack. Is there something that needs
> be included in our service.xml file to tell spring how to cleanup CXF? Is this maybe
a bug
> in CXF that the CXFBusImpl.shutdown(Boolean) just isn't getting called at all or maybe
> in BusFactory.setThreadDefaultBus(Bus) that there should be some check such as:
>   if (bus == null) {
>     localBus.remove();
>   } else {
>     localBus.set(bus);
>   }
> Or maybe some combination of all of these. I'm reasonably new to CXF, Spring, and all
> stuff so I apologize ahead of time if there is some obvious solution that I just didn't
> across but I've been trying to scour the CXF and Spring documentation for some idea of
> correct way to do this and why BusFactory is keeping its ThreadLocal but I can't figure
> out.
> Thanks!
> Ben Dean
> Software Engineer
> Ontario Systems, LLC

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message