Class ApplicationLifecycleManager


  • public class ApplicationLifecycleManager
    extends Object
    Manages the lifecycle of a Quarkus application. The Application class is responsible for starting and stopping the application, but nothing else. This class can be used to run both persistent applications that will run till they receive a signal, and command mode applications that will run until the main method returns. This class registers a shutdown hook to properly shut down the application, and handles exiting with the supplied exit code as well as any exception thrown when starting the application. This class should be used to run production and dev mode applications, while test use cases will likely want to just use Application directly. This class is static, there can only ever be a single application instance running at any time.
    • Method Detail

      • getExitCode

        public static int getExitCode()
        Returns:
        The current exit code that would be reported if the application exits
      • exit

        public static void exit()
        Exits without supplying an exit code. The application will exit with a code of 0 by default, however if this method is called it is still possible for a different exit code to be set.
      • isVmShuttingDown

        public static boolean isVmShuttingDown()
        Returns:
        true if the VM is shutting down
      • setDefaultExitCodeHandler

        public static void setDefaultExitCodeHandler​(BiConsumer<Integer,​Throwable> defaultExitCodeHandler)
        Sets the default exit code and exception handler for application run through the run method that does not take an exit handler. By default this will just call System.exit, however this is not always what is wanted.
        Parameters:
        defaultExitCodeHandler - the new default exit handler
      • setDefaultExitCodeHandler

        public static void setDefaultExitCodeHandler​(Consumer<Integer> defaultExitCodeHandler)
        Sets the default exit code handler for application run through the run method that does not take an exit handler. By default this will just call System.exit, however this is not always what is wanted.
        Parameters:
        defaultExitCodeHandler - the new default exit handler
      • exit

        public static void exit​(int code)
        Signals that the application should exit with the given code. Note that the first positive exit code will 'win', so if the exit code has already been set then the exit code will be ignored.
        Parameters:
        code - The exit code
      • waitForExit

        public static void waitForExit()
        Waits for the shutdown process to be initiated.