我想要獲得一個在JBoss Seam 2.2.0.GA中工作的Quartz scheduler的簡單示例。一切工作正常使用RAMJobStore設置,但改變從如何從RAMJobStore遷移到JobStoreCMT在Seam中的持久石英作業
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在postInitialization中沒有運行TX。您是否嘗試將@Transactional放在createQuartzTimer上? – Tair
添加@Transactional沒有開始工作。無論使用哪個註釋,該方法仍然被調用(使用簡單的日誌語句進行檢查)。 – spikeheap
我測試過這個設置: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。 – Tair