public final class Programs extends Object
Modifier and Type | Method | Description |
---|---|---|
static void |
enableVmHeadlessMode() |
Enables the VM's headless mode (i.e., the mode that does not require a
display, keyboard, nor mouse).
|
static void |
runAndExitVm(Program p) |
Runs the specified program and exits the VM with the exit status of the
program.
|
public static void runAndExitVm(Program p)
The program runs in a separate thread, and that thread is interrupted if a VM shutdown is initiated.
The exit status used to exit the VM is the exit status returned by the
program's run()
method. If that method throws an
exception, the exit status used is the exit status returned by the
program's exitStatus(Throwable)
method when passed the exception as its argument. If that method throws an
exception, Program.EXIT_FAILURE
is used.
Before exiting the VM, the program's flush()
method is called to ensure any buffered output gets written to underlying
standard I/O destinations.
NOTE: This method should only be called when the sole purpose of the VM is
to run the specified program. This method does things like registering a
VM shutdown hook and calling System.exit(int)
to exit the VM when
the program terminates. This method normally does not return.
p
- the program to runpublic static void enableVmHeadlessMode()
This is a convenience method that is equivalent to:
System.setProperty("java.awt.headless", "true");