我的目标是通过GlassFish服务器上的Quartz调度程序启动JSR-352批处理作业,但是有一个大问题。首先这是我的密码。
我的JSR-352工作:
<job id="myJob" ...>
<step id="myBatchlet">
<batchlet ref="mypackage.MyBatchlet" />
</step>
</job>相应的Java代码:
public class MyBatchlet implements Batchlet {
@Override
public String process() throws Exception {
System.out.println("Hello World!");
return BatchStatus.COMPLETED.toString();
}
@Override
public void stop() throws Exception {
}
}当我通过servlet在GlassFish 4.0 b89服务器上启动这项工作时,它的工作非常完美:
public class StartJobServlet extends HttpServlet {
private void processRequest(...) throws ... {
long executionId = BatchRuntime.getJobOperator().start("myJob", new Properties());
System.out.println("myJob started, execution ID = " + executionId);
}
}但是现在我想使用Quartz 2.2.3调度程序,所以我用这种方式编写了Quartz作业:
public class StartMyJob implements Job {
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
long executionId = BatchRuntime.getJobOperator().start("myJob", new Properties());
System.out.println("myJob started, execution ID = " + executionId);
}
}我为这份工作配置了Quartz和一个触发器。
但是当myJob应该启动时,它仍然处于启动状态,并且从未真正运行过。
根据日志,实际上启动批处理作业的com.ibm.jbatch.container.util.BatchWorkUnit::run过程从未被调用,而在使用servlet时却是如此。
编辑:我已经找到了其他人的类似问题(相同的症状) 那里,但是所给出的解决方案不能适应,因为我没有glassfish-web.xml文件。
发布于 2017-06-19 14:19:29
使用Quartz在EE服务器中的非托管线程上执行作业将导致使用各种EE的问题,包括Java批处理(JSR 352)。
您可以使用标准的EE (如ManagedScheduledExecutorService,@Schedule等)来代替Quartz。(这方面有很多教程和例子)。
我还没有足够的专家来列出石英的替代品。看起来,如果您可以让Quartz线程使用ManagedExecutorService,运行,那么它将解决这个问题。这个JIRA认为这是添加到兵马俑石英,但我不认为是肯定的。也许也有一种使用开放源码Quartz的方法,要么在服务器外运行Quartz (并远程进入托管线程,比如EJB?,不确定),或者甚至使用我不知道的配置选项。
如果有人能提供一个更好的答案,澄清石英的选择,这将是有帮助的。
https://stackoverflow.com/questions/44495398
复制相似问题