Shutting down is the way to go, but keep in mind that there is no guarantee that the code is actually executed. JVM crashes, power failures, or a simple “kill -9” on your JVM can prevent code flushing. Therefore, you must make sure that your program remains in a stable state, even if it was interrupted abruptly.
Personally, I just use the database for all storage states. The transaction model ensures that persistent storage is in good condition no matter what happens. They spend years making this code flawless, so why should I spend my time on problems that have already been resolved.
Thomas morgner
source share