{"record":{"id":"37969523cb3cb9de","repo":"LMAX-Exchange/disruptor","slug":"all-event-handlers-must-be-added-before-calling-st","errorCode":null,"errorMessage":"All event handlers must be added before calling starts.","messagePattern":"All event handlers must be added before calling starts\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/lmax/disruptor/dsl/Disruptor.java","lineNumber":596,"sourceCode":"    }\n\n    EventHandlerGroup<T> createEventProcessors(\n            final Sequence[] barrierSequences, final EventProcessorFactory<T>[] processorFactories)\n    {\n        final EventProcessor[] eventProcessors = new EventProcessor[processorFactories.length];\n        for (int i = 0; i < processorFactories.length; i++)\n        {\n            eventProcessors[i] = processorFactories[i].createEventProcessor(ringBuffer, barrierSequences);\n        }\n\n        return handleEventsWith(eventProcessors);\n    }\n\n    private void checkNotStarted()\n    {\n        if (started.get())\n        {\n            throw new IllegalStateException(\"All event handlers must be added before calling starts.\");\n        }\n    }\n\n    private void checkOnlyStartedOnce()\n    {\n        if (!started.compareAndSet(false, true))\n        {\n            throw new IllegalStateException(\"Disruptor.start() must only be called once.\");\n        }\n    }\n\n    @Override\n    public String toString()\n    {\n        return \"Disruptor{\" +\n                \"ringBuffer=\" + ringBuffer +\n                \", started=\" + started +\n                \", threadFactory=\" + threadFactory +","sourceCodeStart":578,"sourceCodeEnd":614,"githubUrl":"https://github.com/LMAX-Exchange/disruptor/blob/c871ca49826a6be7ada6957f6fbafcfecf7b1f87/src/main/java/com/lmax/disruptor/dsl/Disruptor.java#L578-L614","documentation":"Thrown by Disruptor's internal checkNotStarted guard: you attempted to modify the consumer graph (handleEventsWith, handleEventsWithWorkerPool, after, handleExceptionsFor, setDefaultExceptionHandler, etc.) after Disruptor.start() was already called. Once started, the wiring is frozen because sequences and barriers have been handed to running threads and mutating them is unsafe.","triggerScenarios":"Calling disruptor.handleEventsWith(...) (or any DSL mutation) after disruptor.start() has run — e.g. lazy registration of an extra consumer triggered by the first event, or a scheduled task adding handlers.","commonSituations":"Dynamically adding consumers at runtime (not supported by Disruptor's DSL); initialization order bug where start() is called in a constructor/@PostConstruct and handlers registered later; retry logic that re-wires handlers after startup.","solutions":["Register all handlers before calling start(); move every handleEventsWith/after call ahead of start().","For genuinely dynamic consumers, create a separate Disruptor or use a WorkPool/worker handler that pulls work dynamically instead of re-wiring.","Review startup order (constructor vs @PostConstruct vs main) so wiring completes first."],"exampleFix":"// before\ndisruptor.handleEventsWith(primaryHandler);\ndisruptor.start();\ndisruptor.handleEventsWith(extraHandler); // IllegalStateException\n\n// after\ndisruptor.handleEventsWith(primaryHandler);\ndisruptor.handleEventsWith(extraHandler);\ndisruptor.start();","handlingStrategy":"validation","validationCode":"if (disruptor.hasStarted()) { // or track your own flag\n    throw new IllegalStateException(\"cannot add handlers after start\");\n}\ndisruptor.handleEventsWith(handler);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Complete all handleEventsWith/after/workerPool wiring in one init method that ends with start().","For dynamic consumers, use worker pools or a separate Disruptor instance instead of post-start wiring."],"tags":["disruptor","dsl","lifecycle","illegal-state","initialization-order"],"backgroundTag":null,"analyzedSha":"c871ca49826a6be7ada6957f6fbafcfecf7b1f87","analyzedAt":"2026-08-14T14:22:36.358Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}