You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ro...@apache.org on 2008/03/19 22:30:41 UTC
svn commit: r639025 -
/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java
Author: rott
Date: Wed Mar 19 14:30:39 2008
New Revision: 639025
URL: http://svn.apache.org/viewvc?rev=639025&view=rev
Log:
AXIS2-3641: memory leaks related to unmarshaller pooling. Thanks to contributor David Strite for the fix!
Modified:
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java?rev=639025&r1=639024&r2=639025&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java Wed Mar 19 14:30:39 2008
@@ -155,23 +155,16 @@
// Get the innerMap
Map<String, JAXBContextValue> innerMap = null;
- if(cacheKey != null) {
- if(log.isDebugEnabled()) {
- log.debug("Using supplied classloader to retrieve JAXBContext: " +
- cacheKey);
- }
- innerMap = jaxbMap.get(cacheKey);
- }else {
- if(log.isDebugEnabled()) {
- log.debug("Using classloader from Thread to retrieve JAXBContext: " +
- cl);
- }
- innerMap = jaxbMap.get(cl);
- }
+ innerMap = getInnerMap(cacheKey, cl);
if (innerMap == null) {
- adjustPoolSize(jaxbMap);
- innerMap = new ConcurrentHashMap<String, JAXBContextValue>();
- jaxbMap.put(cl, innerMap);
+ synchronized(jaxbMap) {
+ innerMap = getInnerMap(cacheKey, cl);
+ if(innerMap==null) {
+ adjustPoolSize(jaxbMap);
+ innerMap = new ConcurrentHashMap<String, JAXBContextValue>();
+ jaxbMap.put(cl, innerMap);
+ }
+ }
}
if (contextPackages == null) {
@@ -180,25 +173,29 @@
JAXBContextValue contextValue = innerMap.get(key);
if (contextValue == null) {
- adjustPoolSize(innerMap);
-
- // Create a copy of the contextPackages. This new TreeSet will
- // contain only the valid contextPackages.
- // Note: The original contextPackage set is accessed by multiple
- // threads and should not be altered.
-
- TreeSet<String> validContextPackages = new TreeSet<String>(contextPackages);
- contextValue = createJAXBContextValue(validContextPackages, cl);
-
- // Put the new context in the map keyed by both the original and valid list of packages
- String validPackagesKey = validContextPackages.toString();
- innerMap.put(key, contextValue);
- innerMap.put(validPackagesKey, contextValue);
- if (log.isDebugEnabled()) {
- log.debug("JAXBContext [created] for " + key);
- log.debug("JAXBContext also stored by the list of valid packages:" + validPackagesKey);
- }
-
+ synchronized (innerMap) {
+ contextValue = innerMap.get(key);
+ if(contextValue==null) {
+ adjustPoolSize(innerMap);
+
+ // Create a copy of the contextPackages. This new TreeSet will
+ // contain only the valid contextPackages.
+ // Note: The original contextPackage set is accessed by multiple
+ // threads and should not be altered.
+
+ TreeSet<String> validContextPackages = new TreeSet<String>(contextPackages);
+ contextValue = createJAXBContextValue(validContextPackages, cl);
+
+ // Put the new context in the map keyed by both the original and valid list of packages
+ String validPackagesKey = validContextPackages.toString();
+ innerMap.put(key, contextValue);
+ innerMap.put(validPackagesKey, contextValue);
+ if (log.isDebugEnabled()) {
+ log.debug("JAXBContext [created] for " + key);
+ log.debug("JAXBContext also stored by the list of valid packages:" + validPackagesKey);
+ }
+ }
+ }
} else {
if (log.isDebugEnabled()) {
log.debug("JAXBContext [from pool] for " + key);
@@ -208,6 +205,24 @@
return contextValue.jaxbContext;
}
+ private static Map<String, JAXBContextValue> getInnerMap(ClassLoader cacheKey, ClassLoader cl) {
+ Map<String, JAXBContextValue> innerMap;
+ if(cacheKey != null) {
+ if(log.isDebugEnabled()) {
+ log.debug("Using supplied classloader to retrieve JAXBContext: " +
+ cacheKey);
+ }
+ innerMap = jaxbMap.get(cacheKey);
+ }else {
+ if(log.isDebugEnabled()) {
+ log.debug("Using classloader from Thread to retrieve JAXBContext: " +
+ cl);
+ }
+ innerMap = jaxbMap.get(cl);
+ }
+ return innerMap;
+ }
+
/**
* Create a JAXBContext using the contextPackages
*
@@ -405,6 +420,7 @@
log.debug("Unmarshaller placed back into pool");
}
if (ENABLE_UNMARSHALL_POOLING) {
+ unmarshaller.setAttachmentUnmarshaller(null);
upool.put(context, unmarshaller);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org