java automatic shutdown

Discussion in 'Mac Programming' started by ashokformac, Apr 18, 2007.

  1. ashokformac macrumors member

    Joined:
    Mar 26, 2007
    #1
    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 ...
     
  2. Wes macrumors 68020

    Wes

    Joined:
    Jun 22, 2001
    Location:
    London
    #2
    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.
     
  3. LtRammstein macrumors 6502a

    LtRammstein

    Joined:
    Jun 20, 2006
    Location:
    Denver, CO
    #3
    Wouldn't be better to just do an Autosave kinda deal with it than having to elaborate on "shutdown"?

    Steve
     
  4. Wes macrumors 68020

    Wes

    Joined:
    Jun 22, 2001
    Location:
    London
    #4
    Without a doubt.
     
  5. Helium3 macrumors newbie

    Joined:
    Oct 8, 2005
    #5
    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.
     
  6. ryan macrumors 6502

    Joined:
    May 17, 2002
    Location:
    Denver, CO
    #6
    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");
       }
    }
     
  7. ashokformac thread starter macrumors member

    Joined:
    Mar 26, 2007
    #7
    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
     
  8. Wes macrumors 68020

    Wes

    Joined:
    Jun 22, 2001
    Location:
    London
    #8
  9. ashokformac thread starter macrumors member

    Joined:
    Mar 26, 2007
    #9
    I tried it but that shutdown hook method was not calling when i stops the program using Stop button in the IDE .....
     

Share This Page