How the JVM processes signals

gangyaocn發表於2012-12-26

When a signal is raised that is of interest to the JVM, a signal handler is called. This signal handler determines whether it has been called for a Java or non-Java thread. If the signal is for a Java thread, the JVM takes control of the signal handling. If the signal is for a non-Java thread, and the application that installed the JVM had previously installed its own handler for the signal, control is given to that handler. Otherwise, the signal is ignored (whether or not this is not the signal's default action).

For exception and error signals the JVM either:

  • Handles the condition and recovers (when the exception is caused by your application code), or
  • Enters a controlled shutdown sequence where it:
    1. Calls your application's signal handler for that signal
    2. Outputs a Javadump, to describe the JVM state at the point of failure
    3. Performs the necessary cleanup to give a clean shutdown

For interrupt signals, the JVM also enters a controlled shutdown sequence, but this time it is treated as a normal termination that:

  • Calls your application's signal handler for that signal
  • Performs the necessary JVM cleanup

The shutdown is identical to the shutdown initiated by a call to the Java method System.exit().

Other signals that are used by the JVM are for internal control purposes and do not cause it to terminate. The only control signal of interest is SIGQUIT, which causes a Javadump to be generated.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26651/viewspace-751659/,如需轉載,請註明出處,否則將追究法律責任。

相關文章