From: rjung Date: Fri, 14 May 2010 17:31:50 +0000 (+0000) Subject: Preparation be fore adding a new leak prevention feature: X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=dbf869c38c5de7d8f42e7b8bd6e9f264ed6c241b;p=tomcat7.0 Preparation be fore adding a new leak prevention feature: change order of features to alphabetic like in listener docs. Makes checking easier. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@944349 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java b/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java index d90995f0b..4a8c5d6e7 100644 --- a/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java +++ b/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java @@ -66,6 +66,19 @@ public class JreMemoryLeakPreventionListener implements LifecycleListener { public void setAppContextProtection(boolean appContextProtection) { this.appContextProtection = appContextProtection; } + + /** + * Protect against the memory leak caused when the first call to + * sun.misc.GC.requestLatency(long) is triggered by a web + * application. This first call will start a GC Daemon thread with the + * thread's context class loader configured to be the web application class + * loader. Defaults to true. + */ + private boolean gcDaemonProtection = true; + public boolean isGcDaemonProtection() { return gcDaemonProtection; } + public void setGcDaemonProtection(boolean gcDaemonProtection) { + this.gcDaemonProtection = gcDaemonProtection; + } /** * Protect against resources being read for JAR files and, as a side-effect, @@ -92,19 +105,6 @@ public class JreMemoryLeakPreventionListener implements LifecycleListener { this.xmlParsingProtection = xmlParsingProtection; } - /** - * Protect against the memory leak caused when the first call to - * sun.misc.GC.requestLatency(long) is triggered by a web - * application. This first call will start a GC Daemon thread with the - * thread's context class loader configured to be the web application class - * loader. Defaults to true. - */ - private boolean gcDaemonProtection = true; - public boolean isGcDaemonProtection() { return gcDaemonProtection; } - public void setGcDaemonProtection(boolean gcDaemonProtection) { - this.gcDaemonProtection = gcDaemonProtection; - } - @Override public void lifecycleEvent(LifecycleEvent event) { // Initialise these classes when Tomcat starts @@ -129,6 +129,41 @@ public class JreMemoryLeakPreventionListener implements LifecycleListener { } /* + * Several components end up calling: + * sun.misc.GC.requestLatency(long) + * + * Those libraries / components known to trigger memory leaks due to + * eventual calls to requestLatency(long) are: + * - javax.management.remote.rmi.RMIConnectorServer.start() + */ + if (gcDaemonProtection) { + try { + Class clazz = Class.forName("sun.misc.GC"); + Method method = clazz.getDeclaredMethod("requestLatency", + new Class[] {long.class}); + method.invoke(null, Long.valueOf(3600000)); + } catch (ClassNotFoundException e) { + if (System.getProperty("java.vendor").startsWith("Sun")) { + log.error(sm.getString( + "jreLeakListener.gcDaemonFail"), e); + } else { + log.debug(sm.getString( + "jreLeakListener.gcDaemonFail"), e); + } + } catch (SecurityException e) { + log.error(sm.getString("jreLeakListener.gcDaemonFail"), e); + } catch (NoSuchMethodException e) { + log.error(sm.getString("jreLeakListener.gcDaemonFail"), e); + } catch (IllegalArgumentException e) { + log.error(sm.getString("jreLeakListener.gcDaemonFail"), e); + } catch (IllegalAccessException e) { + log.error(sm.getString("jreLeakListener.gcDaemonFail"), e); + } catch (InvocationTargetException e) { + log.error(sm.getString("jreLeakListener.gcDaemonFail"), e); + } + } + + /* * Several components end up opening JarURLConnections without first * disabling caching. This effectively locks the file. Whilst more * noticeable and harder to ignore on Windows, it affects all @@ -170,41 +205,6 @@ public class JreMemoryLeakPreventionListener implements LifecycleListener { log.error(sm.getString("jreLeakListener.xmlParseFail"), e); } } - - /* - * Several components end up calling: - * sun.misc.GC.requestLatency(long) - * - * Those libraries / components known to trigger memory leaks due to - * eventual calls to requestLatency(long) are: - * - javax.management.remote.rmi.RMIConnectorServer.start() - */ - if (gcDaemonProtection) { - try { - Class clazz = Class.forName("sun.misc.GC"); - Method method = clazz.getDeclaredMethod("requestLatency", - new Class[] {long.class}); - method.invoke(null, Long.valueOf(3600000)); - } catch (ClassNotFoundException e) { - if (System.getProperty("java.vendor").startsWith("Sun")) { - log.error(sm.getString( - "jreLeakListener.gcDaemonFail"), e); - } else { - log.debug(sm.getString( - "jreLeakListener.gcDaemonFail"), e); - } - } catch (SecurityException e) { - log.error(sm.getString("jreLeakListener.gcDaemonFail"), e); - } catch (NoSuchMethodException e) { - log.error(sm.getString("jreLeakListener.gcDaemonFail"), e); - } catch (IllegalArgumentException e) { - log.error(sm.getString("jreLeakListener.gcDaemonFail"), e); - } catch (IllegalAccessException e) { - log.error(sm.getString("jreLeakListener.gcDaemonFail"), e); - } catch (InvocationTargetException e) { - log.error(sm.getString("jreLeakListener.gcDaemonFail"), e); - } - } } }