Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Using Shutdown Hooks
Using Shutdown Hooks [message #290808] Thu, 01 September 2005 16:12 Go to next message
Eclipse UserFriend
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 #290811 is a reply to message #290808] Thu, 01 September 2005 16:26 Go to previous messageGo to next message
Darin Swanson is currently offline Darin SwansonFriend
Messages: 2386
Registered: July 2009
Senior Member
Not currently supported.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=38016

HTH
Darins

"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
>
Re: Using Shutdown Hooks [message #1098354 is a reply to message #290811] Sat, 31 August 2013 00:54 Go to previous message
Mark Bednarczyk is currently offline Mark BednarczykFriend
Messages: 3
Registered: August 2013
Location: New York
Junior Member
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.
Previous Topic:How do I limit the AboutDialog size for my product in Eclipse 3.8+
Next Topic:How to Create a Console extension
Goto Forum:
  


Current Time: Fri Apr 26 23:22:32 GMT 2024

Powered by FUDForum. Page generated in 0.03282 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top