From bc0d3ee7c03cb669470ad575e4e7a43f00ca5223 Mon Sep 17 00:00:00 2001
From: markt sun.net.www.http.HttpClient is triggered by a web
+ * application. This first call will start a KeepAlive thread with the
+ * thread's context class loader configured to be the web application class
+ * loader. Defaults to true.
+ */
+ private boolean keepAliveProtection = true;
+ public boolean isKeepAliveProtection() { return keepAliveProtection; }
+ public void setKeepAliveProtection(boolean keepAliveProtection) {
+ this.keepAliveProtection = keepAliveProtection;
+ }
+
/**
* Protect against the memory leak, when the initialization of the
* Java Cryptography Architecture is triggered by initializing
@@ -177,6 +190,21 @@ public class JreMemoryLeakPreventionListener implements LifecycleListener {
log.error(sm.getString("jreLeakListener.gcDaemonFail"), e);
}
}
+
+ /*
+ * When a servlet opens a connection using a URL it will use
+ * sun.net.www.http.HttpClient which keeps a static reference to a
+ * keep-alive cache which is loaded using the web application class
+ * loader.
+ */
+ if (keepAliveProtection) {
+ try {
+ Class.forName("sun.net.www.http.HttpClient");
+ } catch (ClassNotFoundException e) {
+ log.error("Could not prevent sun.net.www.http.HttpClient" +
+ " from being loaded.", e);
+ }
+ }
/*
* Creating a MessageDigest during web application startup
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 0a1288002..8cc260050 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -55,6 +55,12 @@
sun.net.www.http.HttpClient. Patch provided by Rob Kooper.
+ (markt)
+ true.
Enables protection so that the KeepAlive thread started by
+ sun.net.www.http.HttpClient does not result in a memory
+ leak. The thread is started the first time the HttpClient
+ class is used. Without this protection, if a web application uses this
+ class the KeepAlive thread will be configured with the thread's context
+ class loader set to the web application class loader which in turn will
+ trigger a memory leak on reload. Defaults to true.
Enables protection so that any token poller thread initialized by
sun.security.pkcs11.SunPKCS11.initToken() does not
--
2.11.0