2

I have a simple one class test to load ehache 2.8.1

Everything is fine however if setting either diskPersistent="true" or overflowToDisk="true" then the VM never terminates.

I have tried setting the shutdown hook but this isn't fired as the thread used by Ehcache isn't a daemon so the vm never gets that far.

<ehcache 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd">
<diskStore path="/temp"/>
<defaultCache
    maxElementsInMemory="100" 
    eternal="false"
    overflowToDisk="false"
/>

<cache 
    name="resolveIpAddresses" 
    maxElementsInMemory="100000" 
    diskPersistent="true"
    overflowToDisk="true"
    eternal="false"         
    timeToLiveSeconds="3600"                
/>
</ehcache>

The ehcache is being managed by a spring 3.1.8 container with the beans

<cache:annotation-driven />
    <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cacheManager-ref="ehcache"/>
<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" p:config-location="/ehcache.xml" p:shared="true"/>

Changing the disk settings to false works fine but obviously not great. How do I tell ehcache that the disk threads are daemon?

Adam Green
  • 181
  • 1
  • 1
  • 4
  • Related answers are available in http://stackoverflow.com/questions/2373431/ehcache-disk-store-unclean-shutdown – Yves Martin Apr 29 '15 at 08:55

1 Answers1

0

If you are using a servlet container, you can use the servlet ShutdownListener, otherwise it's possible to shutdown the disk threads by calling CacheManager.getInstance().shutdown() explicitly in the code.

The Ehcache documentation says that the JVM shutdown hook will:

shutdown the DiskStore. If the DiskStore is persistent, it will write the entries and index > to disk.

The shutdown hook can be explicitly called with a call to System.exit(), in addition to being called when the last non-daemon thread shutdown.

Angular University
  • 42,341
  • 15
  • 74
  • 81