gpt4 book ai didi

java - 在 Openbravo 中同时运行两次的计划进程(使用 Quartz)

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:48:55 26 4
gpt4 key购买 nike

我不太确定这是 Openbravo 问题还是 Quartz 问题,但我们有一些手动流程通过 Openbravo ProcessRequest 对象按计划运行(OB v2.50MP24 ),但这些进程似乎同时运行了两次。 Openbravo 为他们的调度扩展了 Quartz 平台。我已尝试通过确保我的流程类扩展此类来自行解决此问题:

import java.util.List;

import org.openbravo.dal.service.OBDal;
import org.openbravo.model.ad.ui.ProcessRequest;
import org.openbravo.scheduling.ProcessBundle;
import org.openbravo.service.db.DalBaseProcess;

public abstract class RBDDalProcess extends DalBaseProcess {

@Override
protected void doExecute(ProcessBundle bundle) throws Exception {
org.quartz.Scheduler sched = org.openbravo.scheduling.OBScheduler
.getInstance().getScheduler();
int runCount = 0;
synchronized (sched) {
List<org.quartz.JobExecutionContext> currentlyExecutingJobs = (List<org.quartz.JobExecutionContext>) sched
.getCurrentlyExecutingJobs();
for (org.quartz.JobExecutionContext jec : currentlyExecutingJobs) {
ProcessRequest processRequest = OBDal.getInstance().get(
ProcessRequest.class, jec.getJobDetail().getName());
if (processRequest == null)
continue;
String processClass = processRequest.getProcess()
.getJavaClassName();
if (bundle.getProcessClass().getCanonicalName()
.equals(processClass)) {
runCount++;
}
}
}

if (runCount > 1) {
System.out.println("Process "
+ bundle.getProcessClass().getSimpleName()
+ " is already running. Cancelling.");
return;
}

doRun(bundle);
}

protected abstract void doRun(ProcessBundle bundle);

}

当我通过请求进程同时立即运行两次进行测试时,这工作正常。其中一个被取消了。但是,它不适用于计划的流程。我将 S.o.p 设置为在进程启动时记录日志,查看日志会显示输出的每一行两次,每一行都紧接着另一行。

我暗暗怀疑这是因为这些进程要么在两个完全不同的线程中运行,而这两个线程不知道彼此的进程,但是,我不确定如何验证我的怀疑,或者如果我是正确的,该怎么办。我已经验证了数据库中存储的每个 ProcessRequest 对象只有一个实例。

有没有其他人经历过这种情况,知道为什么他们可能会运行两次,或者知道我可以做些什么来防止他们同时运行?

最佳答案

双重作业执行的最常见原因如下:

已编辑:

  • Your application is deployed in a clustered environment and you have not configured Quartz to run in a cluster environment.
  • Your application is deployed more than once. There are many cases where the application is deployed twice especially in Tomcat server. As a consequence the QuartzInitializerListener is invoked twice and the Jobs are executed twice. In case you use Tomcat server and you are defining contexts explicitly in server.xml, you should turn off automatic application deployment or specify deployIgnore. Both the autoDeploy set to true and the context element existence in server.xml, have as a consequence the twice deployment of the application. Set autoDeploy to false or remove the context element from the server.xml.
  • Your application has been redeployed without unscheduling the current processes.

希望对你有帮助

关于java - 在 Openbravo 中同时运行两次的计划进程(使用 Quartz),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11957673/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com