BigMemory 4.4.0 | Product Documentation | BigMemory Go Operations Guide | Shutting Down Ehcache | The Shutdown Hook
 
The Shutdown Hook
The CacheManager can optionally register a shutdown hook. To do so, set the system property net.sf.ehcache.enableShutdownHook=true. This will shut down the CacheManager when it detects the Virtual Machine shutting down and it is not already shut down.
Use the shutdown hook when the CacheManager is not already being shutdown by a framework you are using, or by your application.
Note:
Shutdown hooks are inherently problematic. The JVM is shutting down, so sometimes things that can never be null are. Ehcache guards against as many of these as it can, but the shutdown hook should be the last option to use.
The shutdown hook is on CacheManager. It simply calls the shutdown method. The sequence of events is:
*Call dispose for each registered CacheManager event listener.
*Call dispose for each Cache.
Each Cache will:
*Shutdown the MemoryStore. The MemoryStore will flush to the DiskStore.
*Shutdown the DiskStore. If the DiskStore is persistent ("localRestartable"), it will write the entries and index to disk.
*Shutdown each registered CacheEventListener.
*Set the Cache status to shutdown, preventing any further operations on it.
*Set the CacheManager status to shutdown, preventing any further operations on it.
The shutdown hook runs when:
*A program exists normally. For example, when System.exit() is called, or when the last non-daemon thread exits.
*The Virtual Machine is terminated, e.g., CTRL-C. This corresponds to kill -SIGTERM pid or kill -15 pid on Unix systems.
The shutdown hook will not run when:
*The Virtual Machine aborts.
*A SIGKILL signal is sent to the Virtual Machine process on Unix systems, e.g., kill -SIGKILL pid or kill -9 pid.
*A TerminateProcess call is sent to the process on Windows systems.