Luca Boncompagni created CXF-7591:
-------------------------------------
Summary: memory leak in ClientImpl
Key: CXF-7591
URL: https://issues.apache.org/jira/browse/CXF-7591
Project: CXF
Issue Type: Bug
Components: Core, JAX-WS Runtime
Affects Versions: 3.1.6
Environment: wildfly-10.1.0
Reporter: Luca Boncompagni
My app is a web-app and my wildfly has ~ 300 thread. If I understand correctly
the code, ClientImpl.responseContext is cleaned only on destroy. We use a lot
of service ad some of them have a large output (~10Mb). So, I need a lot of
memory for storing ClientImpl.responseContext.
I try the following patch ant it seems to solve the problem, but it has an
horrible cast.
{{
diff --git a/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
b/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
index 428f79454b..b15fb4dff2 100644
--- a/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
+++ b/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
@@ -29,7 +29,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.WeakHashMap;
+import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.logging.Level;
@@ -96,10 +96,10 @@ public class ClientImpl
protected Map<String, Object> currentRequestContext = new
ConcurrentHashMap<String, Object>(8, 0.75f, 4);
protected Map<Thread, EchoContext> requestContext
- = Collections.synchronizedMap(new WeakHashMap<Thread, EchoContext>());
+ = Collections.synchronizedMap(new HashMap<Thread, EchoContext>());
protected Map<Thread, Map<String, Object>> responseContext
- = Collections.synchronizedMap(new WeakHashMap<Thread, Map<String,
Object>>());
+ = Collections.synchronizedMap(new HashMap<Thread, Map<String,
Object>>());
protected Executor executor;
@@ -1052,5 +1052,8 @@ public class ClientImpl
}
}
-
+ public void releaseLocalThread() {
+ requestContext.remove(Thread.currentThread());
+ responseContext.remove(Thread.currentThread());
+ }
}
diff --git
a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
index d963693afd..37b5e2ed02 100644
--- a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
+++ b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsClientProxy.java
@@ -131,6 +131,7 @@ public class JaxWsClientProxy extends
org.apache.cxf.frontend.ClientProxy implem
client.getRequestContext().put(Method.class.getName(), method);
boolean isAsync = isAsync(method);
+ try {
Object result = null;
try {
if (isAsync) {
@@ -184,6 +185,9 @@ public class JaxWsClientProxy extends
org.apache.cxf.frontend.ClientProxy implem
}
}
return adjustObject(result);
+ } finally {
+ if(client instanceof org.apache.cxf.endpoint.ClientImpl)
((org.apache.cxf.endpoint.ClientImpl)client).releaseLocalThread();
+ }
}
boolean isAsync(Method m) {
return m.getName().endsWith("Async")
}}
Luca
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)