Adding new listener to defragement heap at startup.
This commit is contained in:
parent
e8fed3dfbf
commit
5951f16be0
1 changed files with 40 additions and 0 deletions
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue