Virtual Machine Shutdown Considerations

The DiskStore can optionally be configured to persist between CacheManager and Virtual Machine instances. See documentation on the diskPersistent cache attribute for information on how to do this.

When diskPersistent is turned on for a cache, a Virtual Machine shutdown hook is added to enable the DiskStore to persist itself. When the Virtual Machine shuts down, the the hook runs and, if the cache is not already disposed, it calls dispose. Any elements in the MemoryStore are spooled to the DiskStore. The DiskStore then flushes the spool, and writes the index to disk.

The cache shutdown hooks will run when:

  • a program exists normally. e.g. System.exit() is called, or 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 cache shutdown hooks 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.

If dispose was not called on the cache either by CacheManager.shutdown() or the shutdown hook, then the DiskStore will be corrupt when the application is next started. If this happens, it will be detected and the DiskStore file will be automatically truncated and a log warning level message is emitted. The cache will work normally, except that it will have lost all data.