本文介绍了如何从 RAMJobStore 迁移到 JobStoreCMT 以在 Seam 中持久化 Quartz 作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取在 JBoss Seam 2.2.0.GA 中运行的 Quartz 调度程序的简单示例.使用 RAMJobStore 设置一切正常,但将存储更改为

I am trying to get a simple example of the Quartz scheduler working in JBoss Seam 2.2.0.GA. Everything works fine using the RAMJobStore setting, but changing the store from

org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore

org.quartz.jobStore.class org.quartz.impl.jdbcjobstore.JobStoreCMT
org.quartz.jobStore.driverDelegateClass org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
org.quartz.jobStore.useProperties false
org.quartz.jobStore.dataSource quartzDatasource
## FIXME Should be a different datasource for the non managed connection.
org.quartz.jobStore.nonManagedTXDataSource quartzDatasource
org.quartz.jobStore.tablePrefix qrtz_
org.quartz.dataSource.quartzDatasource.jndiURL java:/quartzDatasource

允许调度程序启动,但是之前作业被触发并以正确的时间间隔运行,现在它根本没有运行.石英数据库中也没有任何内容.

allows the scheduler to start up, but whereas the job was previously being triggered and run at the correct interval, now it is not run at all. There is also nothing persisted to the quartz database.

我知道 nonManagedTXDataSource 不应该与托管数据源相同,但是我遇到了 Quartz 无法找到数据源的问题,即使之前有消息报告它已成功绑定(这可能会在一个单独的问题中提出).使用相同的数据源可以使服务启动而不会出错.

I am aware that the nonManagedTXDataSource shouldn't be the same as the managed datasource, but I am having issues with the datasource being unable to be found by Quartz, even though there is a message earlier on reporting it being bound successfully (this is probably about to be asked in a separate question). Using the same datasource allows the service to start up without errors.

我的 components.xml 文件有以下内容:

My components.xml file has the following:

<event type="org.jboss.seam.postInitialization">
   <action execute="#{asyncResultMapper.scheduleTimer}"/>
</event>
<async:quartz-dispatcher/>

和 ASyncResultMapper 具有以下内容:

and ASyncResultMapper has the following:

@In
ScheduleProcessor processor;
private String text = "ahoy";
private QuartzTriggerHandle quartzTriggerHandle;

public void scheduleTimer() {
    String cronString = "* * * * * ?";
    quartzTriggerHandle = processor.createQuartzTimer(new Date(), cronString, text);
}

和ScheduleProcessor如下:

and ScheduleProcessor is as follows:

@Name("processor")
@AutoCreate
@Startup
@Scope(ScopeType.APPLICATION)
public class ScheduleProcessor {

    @Asynchronous
    public QuartzTriggerHandle createQuartzTimer(@Expiration Date when, @IntervalCron String interval, String text) {
        process(when, interval, text);
        return null;
    }

    private void process(Date when, String interval, String text) {
        System.out.println("when = " + when);
        System.out.println("interval = " + interval);
        System.out.println("text = " + text);
    }
}

日志显示服务正在启动,但没有关于工作:

The logs show the service starting but nothing about the job:

INFO  [QuartzScheduler] Quartz Scheduler v.1.5.2 created.
INFO  [JobStoreCMT] Using db table-based data access locking (synchronization).
INFO  [JobStoreCMT] Removed 0 Volatile Trigger(s).
INFO  [JobStoreCMT] Removed 0 Volatile Job(s).
INFO  [JobStoreCMT] JobStoreCMT initialized.
INFO  [JobStoreCMT] Freed 0 triggers from 'acquired' / 'blocked' state.
INFO  [JobStoreCMT] Recovering 0 jobs that were in-progress at the time of the last shut-down.
INFO  [JobStoreCMT] Recovery complete.
INFO  [JobStoreCMT] Removed 0 'complete' triggers.
INFO  [JobStoreCMT] Removed 0 stale fired job entries.
INFO  [QuartzScheduler] Scheduler FlibScheduler$_NON_CLUSTERED started.

我确定这可能是我遗漏的一些小事,但我无法在任何地方的论坛中找到解决方案.

I'm sure it's probably something trivial I've missed, but I can't find a solution in the forums anywhere.

推荐答案

最终自己设法解决了这个问题.JobStoreCMT 版本无法启动和触发作业的问题是由缺少 @Transactional(感谢 tair)和更重要的是需要升级 Quartz 的混合引起的.Quartz 升级到 1.8.5 后,错误消息变得更加有用.

Managed to solve this for myself in the end. The issue of the JobStoreCMT version not starting and triggering jobs was caused by a mixture of a missing @Transactional (thanks tair), and more importantly a need to upgrade Quartz. Once Quartz was upgraded to 1.8.5 the error messages became a lot more useful.

这篇关于如何从 RAMJobStore 迁移到 JobStoreCMT 以在 Seam 中持久化 Quartz 作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 01:05