public void setAppContextProtection(boolean appContextProtection) {
this.appContextProtection = appContextProtection;
}
+
+ /**
+ * Protect against the memory leak caused when the first call to
+ * <code>sun.misc.GC.requestLatency(long)</code> 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 <code>true</code>.
+ */
+ 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,
this.xmlParsingProtection = xmlParsingProtection;
}
- /**
- * Protect against the memory leak caused when the first call to
- * <code>sun.misc.GC.requestLatency(long)</code> 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 <code>true</code>.
- */
- 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
}
/*
+ * 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
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);
- }
- }
}
}