KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > lang > Terminator


1 /*
2  * @(#)Terminator.java 1.10 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.lang;
9
10 import sun.misc.Signal;
11 import sun.misc.SignalHandler;
12
13
14 /**
15  * Package-private utility class for setting up and tearing down
16  * platform-specific support for termination-triggered shutdowns.
17  *
18  * @author Mark Reinhold
19  * @version 1.10, 03/12/19
20  * @since 1.3
21  */

22
23 class Terminator {
24
25     private static SignalHandler handler = null;
26
27     /* Invocations of setup and teardown are already synchronized
28      * on the shutdown lock, so no further synchronization is needed here
29      */

30
31     static void setup() {
32     if (handler != null) return;
33     SignalHandler sh = new SignalHandler() {
34         public void handle(Signal sig) {
35         Shutdown.exit(sig.getNumber() + 0200);
36         }
37     };
38     handler = sh;
39         try {
40             Signal.handle(new Signal("INT"), sh);
41             Signal.handle(new Signal("TERM"), sh);
42         } catch (IllegalArgumentException JavaDoc e) {
43             // When -Xrs is specified the user is responsible for
44
// ensuring that shutdown hooks are run by calling
45
// System.exit()
46
}
47     }
48
49     static void teardown() {
50     /* The current sun.misc.Signal class does not support
51      * the cancellation of handlers
52      */

53     }
54
55 }
56
Popular Tags