How to remove job in Quartz JDBC Store?

偶尔善良 提交于 2021-01-29 09:11:37

问题


I wrote this method to remove a job from Quartz JDBC

public boolean removeJob(String jobName) {
    try {
        JobKey jobKey = JobKey.jobKey(jobName);  
        try {    
            Scheduler sched = schedulerFactoryBean.getScheduler();  
            logger.info("RESULT: " + sched.deleteJob(jobKey)); 
        } catch (Exception e) {    
            throw new RuntimeException(e);    
        }    
        return true; 
    } catch (Exception ex) {
        logger.error(ex.getMessage());
        return false; 
    } 
} 

deleteJob is always returning false. So the job is not getting removed from the JDBC tables in mysql. What am I doing wrong. I only want to completely remove this job from the scheduler


回答1:


Have you defined a job group during job creation? Then you may need to call jobKey(jobName, group). You can also check if job exists with scheduler.checkExists(jobKey) method which will be good for debugging.

JobKey jobKey = jobKey(jobName, group);
if (scheduler.checkExists(jobKey)) {
    logger.info("job found with key: {}", jobKey); 
    scheduler.deleteJob(jobKey);
}


来源:https://stackoverflow.com/questions/53622605/how-to-remove-job-in-quartz-jdbc-store

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!