Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ashokformac

macrumors member
Original poster
Mar 26, 2007
34
0
when my java program shutdowns automatically or shutdowns when the system shut downs or or when systems crashes ,,, i want to perform some actions like updating database....

how can i do this ...

thanks in advance ...
 
when my java program shutdowns automatically or shutdowns when the system shut downs or or when systems crashes ,,, i want to perform some actions like updating database....

how can i do this ...

thanks in advance ...

Your second requirement seems nigh on impossible. When the system crashes it stops responding and is really in a bad state. There's no real way to have the system call some java program when it has crashed, and even if you did, I doubt that it would in be much of a state to start the JVM.

The other feature you want is possible, but that's what Google is for.
 
Runtime

You can at least partially get what you want by using the addShutdownHook(Thread hook) method on the java.lang.Runtime class. Take a look at the documentation on the Sun website for more information.
 
Depending on exactly what you're trying to accomplish adding a shutdown hook can get you at least partially there:

PHP:
Runtime.getRuntime().addShutdownHook(new ShutdownHookThread());

private class ShutdownHookThread extends Thread {
   public void run() {
       System.out.println("Application shutdown");
   }
}
 
Just i want to perform some action when my program stopped externally...
ie..when stopped by IDE itself or Closing my system tray icon or closing from dock .....

how can i do this ...

thanks in advance
 
I tried it but that shutdown hook method was not calling when i stops the program using Stop button in the IDE .....
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.