Article View: borland.public.jbuilder.java.api
Article #941Re: an idea to consider
From: John McGrath TeamB
Date: Mon, 08 Jul 2002 15:47
Date: Mon, 08 Jul 2002 15:47
43 lines
2900 bytes
2900 bytes
On Sun, 07 Jul 2002 16:18:50 -0400, Alan Shiers wrote:
> This tells me it is waiting itself for a signal to shut the
> program down. How does it know when CTRL+C has been pressed?
The Java shutdown hook has nothing to do with keystrokes. It is
triggered when the virtual machine is shut down. That can happen
as the result of a number of events, including a System.exit() call
in your code or closing a Frame that has a DefaultCloseOperation of
EXIT_ON_CLOSE.
Another way this can happen is for the operating system to tell it
to shut down. On Windows, if you press Ctrl-C from the console of
a console application, it will send a signal to the process telling
it to shut down. Unix has a similar mechanism, the INT signal. By
default this is triggered by a DEL, but on many Linux systems it is
a Ctrl-C. You can also use the "kill" command to send that signal.
The operating system might also kill the Java VM in such a way that it
does not have the opportunity to shut down gracefully. On Unix
systems, if you issue a "kill -9" command, the JVM is terminated
immediately and shutdown hooks will not run.
> While it was running I tried pressing CTRL+C on the keyboard,
> but nothing happens! I was thinking that the Runtime class
> was monitoring for this activity. I guess not...
As I said, the conditions under which the shutdown hooks are run are
operating system dependent. If I run a Java program as a Console
Application on Windows or from a RH Linux terminal window, Ctrl-C will
run the shutdown hooks.
What operating system are you running this on? What command do you use
to run the Java application?
--
Regards,
John McGrath [TeamB]
---------------------------------------------------
Before sending me e-mail, please read:
http://www.JPMcGrath.net/newsgroups/e-mail.html
Technical Details
Message-ID:
<MPG.1793793e26a87ab98b7fd@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!supernews.com!newsfeed.ision.net!ision!news.belwue.de!newsfeed01.sul.t-online.de!newsfeed00.sul.t-online.de!t-online.de!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnewsReferences:
<3D279D25.59AA52E@hfx.eastlink.ca> <3d27a0b2_2@dnews> <3D2861BB.63220DF5@hfx.eastlink.ca> <MPG.17923b35889aef9498b7f9@newsgroups.borland.com> <3D28A22A.89CB73DC@hfx.eastlink.ca>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,4157c064c52214d4 X-Google-Attributes: gid1089d0,public X-Google-ArrivalTime: 2002-07-08 08:57:49 PST From: John McGrath [TeamB] <ng-b@JPMcGrath.net> Newsgroups: borland.public.jbuilder.java.api Subject: Re: an idea to consider Date: Mon, 8 Jul 2002 11:47:03 -0400 Message-ID: <MPG.1793793e26a87ab98b7fd@newsgroups.borland.com> References: <3D279D25.59AA52E@hfx.eastlink.ca> <3d27a0b2_2@dnews> <3D2861BB.63220DF5@hfx.eastlink.ca> <MPG.17923b35889aef9498b7f9@newsgroups.borland.com> <3D28A22A.89CB73DC@hfx.eastlink.ca> X-Newsreader: MicroPlanet Gravity v2.60 NNTP-Posting-Host: 209.92.40.60 X-Trace: dnews 1026143222 209.92.40.60 (8 Jul 2002 08:47:02 -0700) Lines: 43 X-Authenticated-User: jpmcgrath Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!supernews.com!newsfeed.ision.net!ision!news.belwue.de!newsfeed01.sul.t-online.de!newsfeed00.sul.t-online.de!t-online.de!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnews