{"record":{"id":"ba55a76329842747","repo":"quarkusio/quarkus","slug":"quarkus-already-running","errorCode":null,"errorMessage":"Quarkus already running","messagePattern":"Quarkus already running","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"core/runtime/src/main/java/io/quarkus/runtime/ApplicationLifecycleManager.java","lineNumber":118,"sourceCode":"\n    public static void run(Application application, String... args) {\n        run(application, null, null, args);\n    }\n\n    public static void run(Application application, Class<? extends QuarkusApplication> quarkusApplication,\n            BiConsumer<Integer, Throwable> exitCodeHandler, String... args) {\n        boolean alreadyStarted;\n        stateLock.lock();\n        try {\n            //in tests, we might pass this method an already started application\n            //in this case we don't shut it down at the end\n            alreadyStarted = application.isStarted();\n            alreadyStartedCallback.accept(alreadyStarted);\n            if (shutdownHookThread == null) {\n                registerHooks(exitCodeHandler == null ? defaultExitCodeHandler : exitCodeHandler);\n            }\n            if (currentApplication != null && !shutdownRequested) {\n                throw new IllegalStateException(\"Quarkus already running\");\n            }\n            exitCode = -1;\n            exitThrowable = null;\n            shutdownRequested = false;\n            currentApplication = application;\n        } finally {\n            stateLock.unlock();\n        }\n        try {\n\n            application.start(args);\n            // now we are started, we either run the main application or just wait to exit\n            // when we are in AppCDS generation we can't call the bean container, we just want to fall through to the exit\n            if (quarkusApplication != null && !isAppCDSGeneration()) {\n                BeanManager beanManager = CDI.current().getBeanManager();\n                Set<Bean<?>> beans = beanManager.getBeans(quarkusApplication, Any.Literal.INSTANCE);\n                Bean<?> bean = null;\n                for (Bean<?> i : beans) {","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/core/runtime/src/main/java/io/quarkus/runtime/ApplicationLifecycleManager.java#L100-L136","documentation":"ApplicationLifecycleManager.run() guards against a second concurrent Quarkus application in the same JVM: it tracks currentApplication and a shutdownRequested flag. If a current application exists and shutdown has not been requested, running another application instance throws this IllegalStateException. Quarkus historically supports one application per JVM.","triggerScenarios":"Calling Quarkus.run / ApplicationLifecycleManager.run while another Quarkus application instance is still live in the same JVM and its shutdown was never requested.","commonSituations":"Tests that start Quarkus manually (Quarkus.run) in multiple test methods without shutting down; embedding Quarkus in an application server that boots a second instance; leaked application from a failed previous run that never called stop.","solutions":["Shut down the existing application before starting a new one: Quarkus.asyncExit() or app.stop() / ApplicationLifecycleManager shutdown path so shutdownRequested is set.","In tests, use @QuarkusTest lifecycle or ensure @AfterEach/@AfterAll stops the previous instance.","Run each Quarkus application in a separate JVM/process if multiple instances are genuinely needed.","Check for leaked instances from earlier failures and clear them via proper shutdown hooks (registerHooks is skipped only if a hook thread already exists)."],"exampleFix":"// before\nQuarkus.run(MyApp.class);\nQuarkus.run(MyApp.class); // IllegalStateException: Quarkus already running\n// after\nQuarkus.run(MyApp.class);\nQuarkus.asyncExit();\nQuarkus.waitForExit();\nQuarkus.run(MyApp.class);","handlingStrategy":"try-catch","validationCode":"// before starting, ensure no live instance\nif (Quarkus.isStarted()) { // or your own tracking of a prior run\n    throw new IllegalStateException(\"A Quarkus application is already running in this JVM\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    Quarkus.run(App.class, args);\n} catch (IllegalStateException e) {\n    if (\"Quarkus already running\".equals(e.getMessage())) {\n        Quarkus.asyncExit();\n        Quarkus.waitForExit();\n        Quarkus.run(App.class, args);\n    } else throw e;\n}","preventionTips":["Always shut down the previous instance (asyncExit + waitForExit) before booting a new one in the same JVM.","Use @QuarkusTest in tests instead of manual Quarkus.run calls.","Run independent applications in separate JVMs.","Check for leaked instances after failed runs and ensure shutdown hooks run."],"tags":["quarkus","lifecycle","bootstrap","single-instance"],"backgroundTag":"quarkus-already-running","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}