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. package java.lang;
  8. import sun.misc.Signal;
  9. import sun.misc.SignalHandler;
  10. /**
  11. * Package-private utility class for setting up and tearing down
  12. * platform-specific support for termination-triggered shutdowns.
  13. *
  14. * @author Mark Reinhold
  15. * @version 1.10, 03/12/19
  16. * @since 1.3
  17. */
  18. class Terminator {
  19. private static SignalHandler handler = null;
  20. /* Invocations of setup and teardown are already synchronized
  21. * on the shutdown lock, so no further synchronization is needed here
  22. */
  23. static void setup() {
  24. if (handler != null) return;
  25. SignalHandler sh = new SignalHandler() {
  26. public void handle(Signal sig) {
  27. Shutdown.exit(sig.getNumber() + 0200);
  28. }
  29. };
  30. handler = sh;
  31. try {
  32. Signal.handle(new Signal("INT"), sh);
  33. Signal.handle(new Signal("TERM"), sh);
  34. } catch (IllegalArgumentException e) {
  35. // When -Xrs is specified the user is responsible for
  36. // ensuring that shutdown hooks are run by calling
  37. // System.exit()
  38. }
  39. }
  40. static void teardown() {
  41. /* The current sun.misc.Signal class does not support
  42. * the cancellation of handlers
  43. */
  44. }
  45. }