Results 1 to 14 of 14
Thread: shutdownhook, fsem
- 07-02-2008, 06:46 AM #1
Member
- Join Date
- Jul 2008
- Posts
- 7
- Rep Power
- 0
- 07-02-2008, 08:55 AM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
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
- 07-03-2008, 09:34 AM #3
Member
- Join Date
- Jul 2008
- Posts
- 7
- Rep Power
- 0
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
- 07-03-2008, 12:28 PM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
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.
- 07-03-2008, 12:29 PM #5
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
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.
- 07-04-2008, 08:27 AM #6
Member
- Join Date
- Jul 2008
- Posts
- 7
- Rep Power
- 0
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
- 07-04-2008, 08:59 AM #7
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
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.
- 07-04-2008, 09:02 AM #8
Member
- Join Date
- Jul 2008
- Posts
- 7
- Rep Power
- 0
*************EDITED BY CaptainMorgan.*************
THE SHUTDOWN HOOK IS NOT CALLEDLast edited by CaptainMorgan; 07-04-2008 at 09:39 AM.
- 07-04-2008, 09:06 AM #9
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Well then, as I said, you already know the answer, take it out of full screen exclusive mode first. Why did you ask?
- 07-04-2008, 09:08 AM #10
Member
- Join Date
- Jul 2008
- Posts
- 7
- Rep Power
- 0
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
- 07-04-2008, 09:22 AM #11
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
AFAIK, alt-f4 falls into those categories.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.
How did you come by the determination that the shutdown hook is not called?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.
- 07-04-2008, 09:26 AM #12
Member
- Join Date
- Jul 2008
- Posts
- 7
- Rep Power
- 0
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
- 07-04-2008, 09:39 AM #13
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Have you attempted to submit a bug report and force Sun to answer you directly?
Bug Database
- 07-04-2008, 09:41 AM #14
Member
- Join Date
- Jul 2008
- Posts
- 7
- Rep Power
- 0


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks