{"record":{"id":"ca96060b079a83a8","repo":"jeecgboot/JeecgBoot","slug":"error-ca9606","errorCode":null,"errorMessage":"创建定时任务失败","messagePattern":"创建定时任务失败","errorType":"exception","errorClass":"JeecgBootException","httpStatus":null,"severity":"error","filePath":"jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/service/impl/QuartzJobServiceImpl.java","lineNumber":153,"sourceCode":"\t * @param parameter\n\t */\n\tprivate void schedulerAdd(String id, String jobClassName, String cronExpression, String parameter) {\n\t\ttry {\n\t\t\t// 启动调度器\n\t\t\tscheduler.start();\n\n\t\t\t// 构建job信息\n\t\t\tJobDetail jobDetail = JobBuilder.newJob(getClass(jobClassName).getClass()).withIdentity(id).usingJobData(\"parameter\", parameter).build();\n\n\t\t\t// 表达式调度构建器(即任务执行的时间)\n\t\t\tCronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression);\n\n\t\t\t// 按新的cronExpression表达式构建一个新的trigger\n\t\t\tCronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(id).withSchedule(scheduleBuilder).build();\n\n\t\t\tscheduler.scheduleJob(jobDetail, trigger);\n\t\t} catch (SchedulerException e) {\n\t\t\tthrow new JeecgBootException(\"创建定时任务失败\", e);\n\t\t} catch (RuntimeException e) {\n\t\t\tthrow new JeecgBootException(e.getMessage(), e);\n\t\t}catch (Exception e) {\n\t\t\tthrow new JeecgBootException(\"后台找不到该类名：\" + jobClassName, e);\n\t\t}\n\t}\n\n\t/**\n\t * 删除定时任务\n\t * \n\t * @param id\n\t */\n\tprivate void schedulerDelete(String id) {\n\t\ttry {\n\t\t\tscheduler.pauseTrigger(TriggerKey.triggerKey(id));\n\t\t\tscheduler.unscheduleJob(TriggerKey.triggerKey(id));\n\t\t\tscheduler.deleteJob(JobKey.jobKey(id));\n\t\t} catch (Exception e) {","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/jeecgboot/JeecgBoot/blob/96fb33f5ec68516da0b0147da06b2eb0419e063a/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/service/impl/QuartzJobServiceImpl.java#L135-L171","documentation":"Thrown by QuartzJobServiceImpl.schedulerAdd when the Quartz SchedulerException is raised while scheduling a new job (scheduler.scheduleJob). This typically means the job could not be registered with the Quartz scheduler - most often a duplicate JobKey/TriggerKey, scheduler in a bad state, or the scheduler failed to start. The original SchedulerException is chained as the cause.","triggerScenarios":"Adding a Quartz job whose id already exists in the scheduler; scheduler.start() failed; the trigger with the same key already registered; running in clustered Quartz mode where another node holds the key.","commonSituations":"Re-adding a job that was paused but not deleted (the JobKey still lives in the scheduler); restart race in a clustered Quartz deployment; the QRTZ tables are dirty/inconsistent after a failed migration.","solutions":["Check the chained SchedulerException (the 'cause') for the exact Quartz error code - commonly 'ObjectAlreadyExistsException' for a duplicate key.","Ensure schedulerDelete runs before schedulerAdd when reusing the same id; verify the QRTZ_JOB_DETAILS / QRTZ_TRIGGERS tables do not contain a stale row for the id.","In clustered mode, confirm all nodes share the same JDBC store and clock; clean orphaned rows if a node crashed mid-update."],"exampleFix":"// before: schedulerAdd(id=\"42\",...) called while QRTZ_TRIGGERS still has TRIGGER_NAME=\"42\"\n// after:  // delete the stale trigger first\n//         scheduler.pauseTrigger(TriggerKey.triggerKey(\"42\"));\n//         scheduler.unscheduleJob(TriggerKey.triggerKey(\"42\"));\n//         scheduler.deleteJob(JobKey.jobKey(\"42\"));\n//         schedulerAdd(\"42\", ...);","handlingStrategy":"try-catch","validationCode":"// Ensure no stale key before adding\ntry {\n    scheduler.deleteJob(JobKey.jobKey(id));\n} catch (SchedulerException ignore) {}\n// then schedulerAdd(...)","typeGuard":null,"tryCatchPattern":"try {\n    quartzJobService.saveAndSchedule(job);\n} catch (JeecgBootException e) {\n    if (e.getMessage().contains(\"创建定时任务失败\") && e.getCause() instanceof SchedulerException) {\n        // inspect cause; if ObjectAlreadyExistsException, delete stale key then retry once\n    }\n}","preventionTips":["Always call schedulerDelete before schedulerAdd when reusing an id.","Keep the QRTZ tables clean after failed migrations or crashes.","In clustered Quartz, ensure all nodes share the JDBC store and an NTP-synced clock."],"tags":["quartz","scheduling","scheduler","configuration"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}