Results 1 to 14 of 14
  1. #1
    Join Date
    Jul 2008
    Posts
    7
    Rep Power
    0

    Question shutdownhook, fsem

    is there any way to add a shutdown hook to a full screen exclusive mode program?

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Can you add a shutdown hook to any program? If so (and you can), why wouldn't you be able to this one?

    See Runtime

  3. #3
    Join Date
    Jul 2008
    Posts
    7
    Rep Power
    0

    Default

    if you do the normal

    Runtime.getRuntime().addShutdownHook(
    {
    public void run()
    {
    gameQuitFunction();
    }
    });

    it only executes if the program has been restored to a window first:

    private void restoreScreen()
    {
    Window w = gd.getFullScreenWindow();
    if (w != null)
    {
    w.dispose();
    }
    gd.setFullScreenWindow(null);
    }

    if i use a 'normal' way to exit such as pressing a key, the shutdown hook is only called if i call restoreScreen() before quitting the game. If I use alt-f4 or other ways of quitting while the game is running in full screen exclusive mode, the shutdown hook is not called

    // shutdown hook is called:
    public void quitGame()
    {
    restoreScreen();
    System.exit(0);
    }

    // shutdown hook is not called:
    public void quitGame()
    {
    System.exit(0);
    }

    That detailed enough?

    Thanks, Benjamin

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    A shutdownhook is a shutdownhook. When the JVM exits, it will be run. Possibly if the JVM is abnormally aborted, it won't be, but otherwise, it will be. Period. There is no discussion about it. Calling System.exit(whatever) will cause the shutdown hook to be run, regardless of the context it is called in.

  5. #5
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Now, whether or not your "gameQuitFunction();" method will work, if your app was not a normal window before being called, is another question, but the shutdownhook will have been called.

  6. #6
    Join Date
    Jul 2008
    Posts
    7
    Rep Power
    0

    Default

    no, the bottom line is that if you are running the application in full screen exclusive mode and then quit without changing the window to a normal window, the shutdown hook is not called

    If you don't know how to fix it or call a shutting down function in a different way please don't bother to respond

  7. #7
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Well, if you already know the answer, don't bother to ask.

    In any case, the program is exiting (not being forcibly killed), so any shutdown hooks are called.

  8. #8
    Join Date
    Jul 2008
    Posts
    7
    Rep Power
    0

    Default

    *************EDITED BY CaptainMorgan.*************

    THE SHUTDOWN HOOK IS NOT CALLED
    Last edited by CaptainMorgan; 07-04-2008 at 10:39 AM.

  9. #9
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Well then, as I said, you already know the answer, take it out of full screen exclusive mode first. Why did you ask?

  10. #10
    Join Date
    Jul 2008
    Posts
    7
    Rep Power
    0

    Default

    because if the program quits unexpectedly, such as when the user uses alt-f4 or logs out without exiting, i don't have a chance to take it out of fsem before it quits

  11. #11
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    The Java virtual machine shuts down in response to two kinds of events:

    - The program exits normally, when the last non-daemon thread exits or when the exit (equivalently, System.exit) method is invoked, or

    - The virtual machine is terminated in response to a user interrupt, such as typing ^C, or a system-wide event, such as user logoff or system shutdown.
    AFAIK, alt-f4 falls into those categories.

    Shutdown hooks run at a delicate time in the life cycle of a virtual machine and should therefore be coded defensively. They should, in particular, be written to be thread-safe and to avoid deadlocks insofar as possible. They should also not rely blindly upon services that may have registered their own shutdown hooks and therefore may themselves in the process of shutting down. Attempts to use other thread-based services such as the AWT event-dispatch thread, for example, may lead to deadlocks.

    Shutdown hooks should also finish their work quickly. When a program invokes exit the expectation is that the virtual machine will promptly shut down and exit. When the virtual machine is terminated due to user logoff or system shutdown the underlying operating system may only allow a fixed amount of time in which to shut down and exit. It is therefore inadvisable to attempt any user interaction or to perform a long-running computation in a shutdown hook.
    How did you come by the determination that the shutdown hook is not called?

  12. #12
    Join Date
    Jul 2008
    Posts
    7
    Rep Power
    0

    Default

    well i tried putting System.out.println calls into the shutdown hook, and they never worked, and no functions that i put into are ever called either, so i would assume the shutdown hook is never run, especially since you get rid of fsem mode the shutdown hook works normally

    I also saw this question on other forums but it was never answered

  13. #13
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Have you attempted to submit a bug report and force Sun to answer you directly?

    Bug Database

  14. #14
    Join Date
    Jul 2008
    Posts
    7
    Rep Power
    0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •