Class Signals

java.lang.Object
com.codename1.backend.Signals

public final class Signals extends Object

Turns SIGTERM into an ordinary blocking call, so a server can shut down cleanly when its container asks it to.

The handler itself does one async-signal-safe write() to a pipe, and this class turns that into an ordinary blocking read. Calling into the VM from a handler -- allocating, taking a monitor, touching the collector -- is undefined, and blocking the signals and calling sigwait() does not work either: ParparVM starts its collector thread before main(), so that thread never inherits the mask and dies on the default action.

  • Method Details

    • installShutdownHandler

      public static boolean installShutdownHandler()
      Installs the shutdown handlers and ignores SIGPIPE. Safe to call more than once. Writing to a socket whose peer has gone is routine for a server, and SIGPIPE's default action is to kill the process; ignored, the write returns an error like any other.
    • awaitShutdownSignal

      public static int awaitShutdownSignal()
      Blocks until SIGINT or SIGTERM arrives. Returns the signal number, or -1.
    • onShutdown

      public static void onShutdown(Runnable body)
      Runs body on a dedicated thread when a shutdown signal arrives. blockShutdownSignals must already have been called.