Tuesday, December 21, 2004

Surviving Abrupt Shutdown

Nice article for doing tasks before the program exits. Surviving Abrupt Shutdown

Now I have the following lines of code in the constructor :

shutdownHook = new ShutdownHook();
Runtime.getRuntime().addShutdownHook(shutdownHook);

and the new ShutdownHook class takes a snapshot of the Prevayler system.

/*
* Created on Dec 22, 2004
* @author Bala Paranj
*/
package com.zepho.mailer;

import com.zepho.persistence.UserDAO;

public class ShutdownHook extends Thread {
public void run() {
System.out.println("Taking Prevayler system snapshot before shut down...");
UserDAO userDAO = new UserDAO();
userDAO.backup();// TODO: backup must be taken only once every 24 hours.
}
}

Thus avoiding the reading of commands from multiple files during system startup. This speeds up the system startup.

No comments:

Post a Comment