*During the startup phase, I have some code that checks things like environment status, remote resource availability, etc...
How can I initiate a clean shutdown at that time?*
You need to write an MBean and in its startService() method you start a non-daemon thread which invokes System.exit(-1).
// The lifecycle
protected void startService() throws Exception
{
log.info("Starting with message=" + message);
boolean problem = false;
log.info("checking some stuff...");
//...
log.info("oops found some problem!");
problem = true;
//...
if(problem) {
Thread myThread = new Thread() {
public void run()
{
log.info("Shutting down");
System.exit(-1);
}
};
myThread.setDaemon(false);
myThread.start();
}
}
The source code is attached.
Comments