diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/HeapDefragement.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/HeapDefragement.java new file mode 100644 index 000000000..1ae839a4d --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/HeapDefragement.java @@ -0,0 +1,40 @@ +package edu.cornell.mannlib.vitro.webapp.servlet.setup; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * This class will request a full garbage collection when + * contextInitialized() is called. The goal is to eliminate fragmentation + * in the tenured generation and avoid problems with the 'young generation guarantee.' + * + * This should be the last listener before the context starts. + * + * See http://blogs.sun.com/jonthecollector/entry/when_the_sum_of_the (retrieved 2010-10-18) + * + * @author bdc34 + * + */ +public class HeapDefragement implements ServletContextListener { + private static final Log log = LogFactory.getLog(HeapDefragement.class); + + @Override + public void contextInitialized(ServletContextEvent arg0) { + try{ + log.info("Calling System.gc() to defragement the heap."); + long start = System.currentTimeMillis(); + System.gc(); + log.info("GC took " + (System.currentTimeMillis() - start) + " msec"); + }catch(Exception ex){ + log.error(ex,ex); + } + } + + @Override + public void contextDestroyed(ServletContextEvent arg0) { + //do nothing + } +}