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?
"Loris" <L.Ugolini@NO_SPAM_quinary.it> wrote in message
news:83cd60acbe9e739fcbfaaf1b6b6b07dd$1@www.eclipse.org...
> 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
>