@LimitedPrivate({"HDFS","MapReduce","YARN"})
@Unstable
public final class ExitUtil
extends java.lang.Object
System.exit(int)
or Runtime.halt(int) MUST invoke it via these methods.| Modifier and Type | Class | Description |
|---|---|---|
static class |
ExitUtil.ExitException |
An exception raised when a call to
terminate(int) was
called and system exits were blocked. |
static class |
ExitUtil.HaltException |
An exception raised when a call to
terminate(int) was
called and system halts were blocked. |
| Modifier and Type | Field | Description |
|---|---|---|
static java.lang.String |
EXIT_EXCEPTION_MESSAGE |
Message raised from an exit exception if none were provided: "ExitException".
|
static java.lang.String |
HALT_EXCEPTION_MESSAGE |
Message raised from a halt exception if none were provided: "HaltException".
|
| Modifier and Type | Method | Description |
|---|---|---|
static void |
disableSystemExit() |
Disable the use of System.exit for testing.
|
static void |
disableSystemHalt() |
Disable the use of
Runtime.getRuntime().halt() for testing. |
static ExitUtil.ExitException |
getFirstExitException() |
|
static ExitUtil.HaltException |
getFirstHaltException() |
|
static void |
halt(int status) |
Forcibly terminates the currently running Java virtual machine.
|
static void |
halt(int status,
java.lang.String message) |
Forcibly terminates the currently running Java virtual machine.
|
static void |
halt(int status,
java.lang.Throwable t) |
Forcibly terminates the currently running Java virtual machine.
|
static void |
halt(ExitUtil.HaltException he) |
Halts the JVM if halt is enabled, rethrow provided exception or any raised error otherwise.
|
static boolean |
haltCalled() |
|
static void |
haltOnOutOfMemory(java.lang.OutOfMemoryError oome) |
Handler for out of memory events -no attempt is made here
to cleanly shutdown or support halt blocking; a robust
printing of the event to stderr is all that can be done.
|
static void |
resetFirstExitException() |
Reset the tracking of process termination.
|
static void |
resetFirstHaltException() |
Reset the tracking of process termination.
|
static void |
terminate(int status) |
Like
terminate(int, Throwable) without a message. |
static void |
terminate(int status,
java.lang.String msg) |
Terminate the current process.
|
static void |
terminate(int status,
java.lang.Throwable t) |
Like
terminate(int, String) but uses the given throwable to
build the message to display or throw as an
ExitUtil.ExitException. |
static void |
terminate(ExitUtil.ExitException ee) |
Exits the JVM if exit is enabled, rethrow provided exception or any raised error otherwise.
|
static boolean |
terminateCalled() |
public static final java.lang.String EXIT_EXCEPTION_MESSAGE
public static final java.lang.String HALT_EXCEPTION_MESSAGE
public static void disableSystemExit()
public static void disableSystemHalt()
Runtime.getRuntime().halt() for testing.public static boolean terminateCalled()
public static boolean haltCalled()
public static ExitUtil.ExitException getFirstExitException()
ExitException thrown, null if none thrown yet.public static ExitUtil.HaltException getFirstHaltException()
HaltException thrown, null if none thrown yet.public static void resetFirstExitException()
public static void resetFirstHaltException()
public static void terminate(ExitUtil.ExitException ee) throws ExitUtil.ExitException
ee - exit exceptionExitUtil.ExitException - if System.exit(int) is disabled and not suppressed by an Errorjava.lang.Error - if System.exit(int) is disabled and one Error arise, suppressing
anything else, even eepublic static void halt(ExitUtil.HaltException he) throws ExitUtil.HaltException
he.
If halt is enabled, all throwables are caught, even errors.he - the exception containing the status code, message and any stack
trace.ExitUtil.HaltException - if Runtime.halt(int) is disabled and not suppressed by an Errorjava.lang.Error - if Runtime.halt(int) is disabled and one Error arise, suppressing
anyuthing else, even hepublic static void terminate(int status,
java.lang.Throwable t)
throws ExitUtil.ExitException
terminate(int, String) but uses the given throwable to
build the message to display or throw as an
ExitUtil.ExitException.
status - exit code to use if the exception is not an ExitException.t - throwable which triggered the termination. If this exception
is an ExitUtil.ExitException its status overrides that passed in.ExitUtil.ExitException - if System.exit(int) is disabled.public static void halt(int status,
java.lang.Throwable t)
throws ExitUtil.HaltException
status - exit code to use if the exception is not a HaltException.t - throwable which triggered the termination. If this exception
is a ExitUtil.HaltException its status overrides that passed in.ExitUtil.HaltException - if System.exit(int) is disabled.public static void terminate(int status)
throws ExitUtil.ExitException
terminate(int, Throwable) without a message.status - exit codeExitUtil.ExitException - if System.exit(int) is disabled.public static void terminate(int status,
java.lang.String msg)
throws ExitUtil.ExitException
status - exit codemsg - message used to create the ExitExceptionExitUtil.ExitException - if System.exit(int) is disabled.public static void halt(int status)
throws ExitUtil.HaltException
status - status codeExitUtil.HaltException - if Runtime.halt(int) is disabled.public static void halt(int status,
java.lang.String message)
throws ExitUtil.HaltException
status - status codemessage - messageExitUtil.HaltException - if Runtime.halt(int) is disabled.public static void haltOnOutOfMemory(java.lang.OutOfMemoryError oome)
oome - out of memory eventCopyright © 2008–2025 Apache Software Foundation. All rights reserved.