Using Shutdown Hooks [message #290808] |
Thu, 01 September 2005 16:12 |
Eclipse User |
|
|
|
Originally posted by: L.Ugolini.NO_SPAM_quinary.it
Hi all,
I tried to use Runtime.getRuntime().addShutdownHook() by clicking
terminate in Eclipse and it never calls the shutdown hook.
Here's the code:
public static void main(String[] args) throws Exception
{
System.setOut(new PrintStream(new File("TrapExit.out")));
Thread shutdownHook = new Thread()
{
public void run()
{
System.out.println("*** END ***");
}
};
Runtime.getRuntime().addShutdownHook(shutdownHook);
while (true)
{
Thread.sleep(100);
System.out.print(".");
}
}
It works fine out of Eclipse, as launching it via command line and then
closing the windows after a while, I actually find the String ""*** END
***"" in the output file.
Note also that if I remove the row "while (true)" it works fine both in
and out of Eclipse.
Does anyone know if there is a way to make it works by clicking the
terminate button inside Eclipse?
Thanks a lot,
Loris
|
|
|
|
Re: Using Shutdown Hooks [message #1098354 is a reply to message #290811] |
Sat, 31 August 2013 00:54 |
|
Here is a write up and download of a work around. This may work for some and is a fairly straight forward work around:
jnetpcap.com/node/1106
Since we rig the exit to call System.exit(0) instead of relying on Elicpses abrupt shutdown the VM hooks are executed.
|
|
|
Powered by
FUDForum. Page generated in 0.04078 seconds