• Bug
  • Status: Closed
  • Resolution: Fixed
  • drb
  • Reporter: sourceforgetracker
  • September 21, 2009
  • 0
  • Watchers: 0
  • September 22, 2009
  • September 22, 2009

Description

When using ehcache as hibernate 2nd level cache with RMI replication persisting cache to disk on application server shutdown doesnt work. Ehcache creates 0 sized files upon startup and does not write to them anything upon JBoss shutdown. Manually flushing cache contents to disk works as expected.

My ehcache.xml:

<?xml version=”1.0” encoding=”UTF-8”?>

Sourceforge Ticket ID: 2445309 - Opened By: nobody - 18 Dec 2008 13:56 UTC

Comments

Sourceforge Tracker 2009-09-21

Ehcache used to come with a shutdown hook for cleanly shutting the cache down but it was troublesome when servers and other frameworks had shutdown hooks.

In you use case, try wiring this up to JBoss:

public class ShutdownListener implements ServletContextListener {

private static final Logger LOG = Logger.getLogger(ShutdownListener.class.getName());

/**
 * Notification that the web application is ready to process requests.
 *
 * @param servletContextEvent
 */
public void contextInitialized(ServletContextEvent servletContextEvent) {
    //nothing required
}

/**
 * Notification that the servlet context is about to be shut down.
 * <p/>
 * Shuts down all cache managers known to {@link CacheManager#ALL_CACHE_MANAGERS}
 *
 * @param servletContextEvent
 */
public void contextDestroyed(ServletContextEvent servletContextEvent) {
    List knownCacheManagers = CacheManager.ALL_CACHE_MANAGERS;
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Shutting down " + knownCacheManagers.size() + " CacheManagers.");
    }
    while (!knownCacheManagers.isEmpty()) {
        ((CacheManager) CacheManager.ALL_CACHE_MANAGERS.get(0)).shutdown();
    }
} \}

by adding the following to web.xml:

net.sf.ehcache.constructs.web.ShutdownListener

Alternatively enable the shutdown hook in ehcache by adding a system property “net.sf.ehcache.enableShutdownHook=true” to your JBoss startup. Comment by: gregluck - 4 Apr 2009 07:42 UTC

Fiona OShea 2009-09-22

Re-opening so that I can properly close out these issues and have correct Resolution status in Jira