{"record":{"id":"1486a726df81affc","repo":"xuxueli/xxl-job","slug":"xxl-job-load-executor-instance-fail-p","errorCode":null,"errorMessage":">>>>>>>>>>> xxl-job load executor instance fail, please initialize it.","messagePattern":">>>>>>>>>>> xxl-job load executor instance fail, please initialize it\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"xxl-job-core/src/main/java/com/xxl/job/core/executor/XxlJobExecutor.java","lineNumber":41,"sourceCode":"import java.util.List;\nimport java.util.Map;\nimport java.util.concurrent.ConcurrentHashMap;\nimport java.util.concurrent.ConcurrentMap;\nimport java.util.concurrent.TimeUnit;\n\n/**\n * Created by xuxueli on 2016/3/2 21:14.\n */\npublic class XxlJobExecutor  {\n    private static final Logger logger = LoggerFactory.getLogger(XxlJobExecutor.class);\n\n\n    // ---------------------- instance ----------------------\n\n    private static XxlJobExecutor xxlJobExecutor = null;\n    public static XxlJobExecutor getInstance() {\n        if (xxlJobExecutor == null) {\n            throw new RuntimeException(\">>>>>>>>>>> xxl-job load executor instance fail, please initialize it.\");\n        }\n        return xxlJobExecutor;\n    }\n\n\n    // ---------------------- field ----------------------\n\n    private String adminAddresses;                                  // admin address list, such as \"http://address\" or \"http://address01,http://address02\"\n    private int timeout = 3;                                        // timeout by second, default 3s\n    private boolean enabled = true;                                 // executor enable, default true\n    private String appname;                                         // executor appname\n    private String accessToken;                                     // access token\n    private String ip;                                              // executor server-info\n    private int port;\n    private String address;                                         // executor registry-address: default use address to registry , otherwise use ip:port if address is null\n    private String logPath = \"/data/applogs/xxl-job/jobhandler\";    // executor log-path\n    private int logRetentionDays = 30;                              // executor log-retention-days\n    private boolean glueEnabled = true;                             // executor glue (non-BEAN) task enable, default true","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/xuxueli/xxl-job/blob/e74c784f68f81fa89cb350913ef15794865d7b12/xxl-job-core/src/main/java/com/xxl/job/core/executor/XxlJobExecutor.java#L23-L59","documentation":"Thrown by XxlJobExecutor.getInstance() when the static singleton field xxlJobExecutor is null. The singleton is only assigned inside start() (xxlJobExecutor = this), so any caller of getInstance() before a successful start() - or after the executor was never started - hits this.","triggerScenarios":"Calling XxlJobExecutor.getInstance() before XxlJobExecutor.start() completed, or in a context where the executor bean was never started (e.g. a test, a misconfigured Spring context, or a startup ordering problem).","commonSituations":"Application lifecycle race where a component autowires and queries the executor during construction before start() runs; unit tests that call core APIs without booting the executor; disabled executor (enabled=false) so start() returns early without binding the singleton.","solutions":["Ensure XxlJobExecutor.start() is called (e.g. via Spring @PostConstruct or a SmartLifecycle) before any code calls getInstance().","Check that the executor is enabled (enabled=true); a disabled executor returns from start() without binding the instance.","In tests, construct and start() the executor explicitly before exercising getInstance()."],"exampleFix":"// before\nIJobHandler h = XxlJobExecutor.getInstance().loadJobHandler(name); // NPE-ish: not started\n// after\nXxlJobExecutor exec = new XxlJobExecutor();\nexec.setAdminAddresses(addr); exec.setAppname(app); exec.setAccessToken(token);\nexec.start(); // binds singleton\nIJobHandler h = XxlJobExecutor.getInstance().loadJobHandler(name);","handlingStrategy":"validation","validationCode":"// Only call getInstance() after a successful start()\nif (XxlJobExecutor.getInstance() == null) { // note: getInstance itself throws; track started flag instead\n    throw new IllegalStateException(\"executor not started\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    XxlJobExecutor.getInstance();\n} catch (RuntimeException e) {\n    log.error(\"executor not initialized; call start() first: {}\", e.getMessage());\n}","preventionTips":["Start the executor in a single well-defined lifecycle hook before any getInstance() call.","Keep a boolean 'started' flag rather than probing the singleton.","Ensure enabled=true so start() binds the instance."],"tags":["lifecycle","singleton","startup","configuration"],"backgroundTag":null,"analyzedSha":"e74c784f68f81fa89cb350913ef15794865d7b12","analyzedAt":"2026-08-14T04:22:43.715Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}