Added method to register shutdown hook for closing self when JVm shuts
down