[ https://issues.apache.org/jira/browse/CXF-2985?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Mauro Molinari updated CXF-2985: -------------------------------- Attachment: Patch_CXF-2985.patch This patch does the following: - adds org.apache.cxf.bus.CXFBusImpl.shutdown() (which calls org.apache.cxf.bus.CXFBusImpl.shutdown(boolean)) and makes cxf.xml declare destroy-method="shutdown" - replaces the ThreadLocal implementation of the localBus relationship in org.apache.cxf.BusFactory with a synchronized WeakHashMap<Thread, Bus> - adds the new method org.apache.cxf.BusFactory.clearDefaultBusForAnyThread(Bus) which removes any entry in the WeakHashMap that has a given bus as a value - makes org.apache.cxf.bus.CXFBusImpl.shutdown(boolean) also call that new method Please note that org.apache.cxf.BusFactory.getThreadDefaultBus(boolean) and org.apache.cxf.BusFactory.possiblySetDefaultBus(Bus) require synchronization because a concurrent call to org.apache.cxf.BusFactory.clearDefaultBusForAnyThread(Bus) may modify the map in the middle of those methods. I hope this helps. > Memory leak when initializing CXF throughSpring > ----------------------------------------------- > > Key: CXF-2985 > URL: https://issues.apache.org/jira/browse/CXF-2985 > Project: CXF > Issue Type: Bug > Components: Bus > Affects Versions: 2.2.10 > Reporter: Mauro Molinari > Priority: Critical > Attachments: Patch_CXF-2985.patch > > > As described in a comment of bug CXF-2164, there's still a case of memory > leak produced by CXF when embedded into a web application and initialized > through Spring. > The problem is that cxf.xml declares the following bean: > <bean id="cxf" class="org.apache.cxf.bus.CXFBusImpl"/> > Here, the destroy-method is not declared. This means that when Sping shuts > down the context, it does not call any shutdown method on the CXFBusImpl. > The net result is the following: > - Tomcat starts > - Tomcat starts my web application > - this declares a Spring web application context that gets parsed > - at some point cxf.xml is parsed, so the bean named cxf is created and an > org.apache.cxf.bus.CXFBusImpl instance is created using the constructor > org.apache.cxf.bus.CXFBusImpl.CXFBusImpl(Map<Class, Object>), which causes > the org.apache.cxf.BusFactory.localBus ThreadLocal to be assigned a value of > this type, through a call to > org.apache.cxf.BusFactory.possiblySetDefaultBus(Bus); I see that this happens > in a thread called "main" > - if I stop the web application, Spring closes down the context; however, as > I said before, this does not cause any shutdown method of the cxf bean to be > called > - so there's no null-setting or removing operation of the > org.apache.cxf.BusFactory.localBus ThreadLocal for the thread "main" > The problem of the use of a ThreadLocal is that even if the shutdown method > od CXFBusImpl were called, the shutdown operation may be done in a thread > which is different from the one in which the context had been created. > As suggested by Daniel Kulp in the other report, maybe the best solution is > to use a WeakHashMap<Thread, Bus> to keep the thread-bus relationships. > I'm going to provide a patch. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.