Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

job在通过 JobOperateAPI.remove()后再 JobScheduler init 创建相同job后会导致 “立即执行一次” trigger 多次执行 #246

Closed
lengfo opened this issue Mar 18, 2017 · 1 comment
Labels

Comments

@lengfo
Copy link
Contributor

lengfo commented Mar 18, 2017

问题描述见标题,我大概找到了问题原因:
主要是因为 JobScheduleController 在 shutdown 的时候没有同时释放 regCenter treeCache 缓存中的listenner,每次init() job 都会重复 addListener。( 这个问题应该不只是trigger有, 比如JobPausedStatusJobListenner 都可能会被重复add ),我现在的解决办法是在调用 JobScheduler init的之前先执行下面这段代码,这样可以避免这个问题:

val cachePath = "/" + job.getJobName();
val cache = (TreeCache) regCenter.getRawCache(cachePath);
if (cache != null) {
log.info("任务【" + job.getJobName() + "】clear regCenter cache " + cachePath);
cache.close();
regCenter.remove(cachePath);
}

我不是特别肯定这是程序bug,或者有其它的考虑,请亮哥判断下。
根本的问题是 Quartz 的 原生 schedule 里面的 trigger 对象被添加了好多次,如果重启服务器则不会有这个问题。
问题分析中源码的关键位置:

JobNodeStorage.java
/**
* 注册数据监听器.
*
* @param listener 数据监听器
*/
public void addDataListener(final TreeCacheListener listener) {
TreeCache cache = (TreeCache) regCenter.getRawCache("/" + jobName);
cache.getListenable().addListener(listener);
}

JobOperationListenerManager.java
@OverRide
public void start() {
addConnectionStateListener(new ConnectionLostListener());
addDataListener(new JobTriggerStatusJobListener());
addDataListener(new JobPausedStatusJobListener());
addDataListener(new JobShutdownStatusJobListener());
}

@lengfo lengfo changed the title job在通过 JobOperateAPI.remove()后再通过 JobScheduler init 创建相同job后会导致 “立即执行一次” api trigger 多次执行的问题 job在通过 JobOperateAPI.remove()后再 JobScheduler init 创建相同job后会导致 “立即执行一次” trigger 多次执行 Mar 18, 2017
@terrymanu terrymanu added the bug label Mar 21, 2017
@terrymanu
Copy link
Member

多谢帮忙分析bug,会在新版本中修复

terrymanu added a commit that referenced this issue Mar 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants