Run a script only at shutdown (not log off or restart) on Mac OS X

Few days ago I published on github a configuration/script able to be executed at boot/shutdown. Basically on Mac OS X you could/should use a System wide and per-user daemon/agent configuration file (plist) in conjunction with a bash script file. This is a sample of the plist file you could use: <?xml version=”1.0″ encoding=”UTF-8″?> <!DOCTYPE plist … Read more

Windows shutdown hook on java application run from a bat script

From addShutdownHook documentation: In rare circumstances the virtual machine may abort, that is, stop running without shutting down cleanly. This occurs when the virtual machine is terminated externally, for example with the SIGKILL signal on Unix or the TerminateProcess call on Microsoft Windows. So i think nothing to do here, unfortunately. CTRL-CLOSE signal in Windows … Read more

Useful example of a shutdown hook in Java?

You could do the following: Let the shutdown hook set some AtomicBoolean (or volatile boolean) “keepRunning” to false (Optionally, .interrupt the working threads if they wait for data in some blocking call) Wait for the working threads (executing writeBatch in your case) to finish, by calling the Thread.join() method on the working threads. Terminate the … Read more