【问题标题】:How to migrate from RAMJobStore to JobStoreCMT for persisted Quartz jobs in Seam如何从 RAMJobStore 迁移到 JobStoreCMT 以在 Seam 中持久化 Quartz 作业
【发布时间】:2011-10-08 15:11:54
【问题描述】:

我正在尝试获取一个在 JBoss Seam 2.2.0.GA 中工作的 Quartz 调度程序的简单示例。使用 RAMJobStore 设置一切正常,但是从

更改存储
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

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

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

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

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

并且 ASyncResultMapper 具有以下内容:

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

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

而ScheduleProcessor如下:

@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);
    }
}

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

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.

我确定这可能是我错过的一些小事,但我在任何地方的论坛中都找不到解决方案。

【问题讨论】:

  • 当使用 CMT Quartz 不处理事务时,这是 Seam 的责任。所以你的 createQuartzTimer 应该在 TX 中运行。 AFAIK 在初始化后没有运行 TX。您是否尝试将 @Transactional 放在 createQuartzTimer 上?
  • 添加@Transactional 并没有开始这项工作。无论使用哪个注解,该方法仍会被调用(使用简单的日志记录语句检查)。
  • 我已经测试了这个设置:JBoss EAP 5.1.1 + Seam 2.2.2 + quartz 1.6.5 + Postgresql 9.1(我们在我们的项目中使用它)并且它工作正常。您的日志显示您使用的是与 JBoss AS 捆绑在一起的旧版 1.5.2 石英,但 Seam 已针对 1.6 api 进行了测试。

标签: java seam quartz-scheduler scheduler


【解决方案1】:

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

【讨论】:

  • 我认为你的意思实际上是@Transactional
猜你喜欢
  • 2011-12-03
  • 1970-01-01
  • 1970-01-01
  • 2011-07-18
  • 2013-09-05
  • 1970-01-01
  • 2012-05-28
  • 1970-01-01
  • 2021-11-12
相关资源
最近更新 更多