使用 Quartz 1.8.3 和 JBoss 7.1.1 并使用以下属性文件:
#============================================================================
# Configure Main Scheduler Properties
#============================================================================
org.quartz.scheduler.instanceName = MyScheduler
org.quartz.scheduler.instanceId = AUTO
#============================================================================
# Configure ThreadPool
#============================================================================
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 25
org.quartz.threadPool.threadPriority = 5
#============================================================================
# Configure JobStore
#============================================================================
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreCMT
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.useProperties = false
org.quartz.jobStore.dataSource = quartzDS
org.quartz.jobStore.nonManagedTXDataSource = quartzDSNoTx
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.jobStore.clusterCheckinInterval = 20000
org.quartz.jobStore.isClustered = false
org.quartz.jobStore.acquireTriggersWithinLock=true
#============================================================================
# Configure Datasources
#============================================================================
org.quartz.dataSource.quartzDS.jndiURL= java:jboss/datasources/myDS
org.quartz.dataSource.quartzDSNoTx.jndiURL= java:jboss/datasources/myDS
#============================================================================
# Quartz Plugin
#============================================================================
org.quartz.plugin.jobstop.class = com.viagents.quartz.JobStopPlugin
org.quartz.plugin.jobstop.tablePrefix = QRTZ_
我初始化 Quartz 的方式是在如下所示的方法上使用 @Singleton、@Startup 和 @PostConstruct 注释:
@EjbInterface(type = EjbInterface.Type.LOCAL)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void startJobs() {
try {
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
this.registerJMX(scheduler);
scheduler.start();
...........................................
}
如果 org.quartz.jobStore.isClustered 属性为 false,我无法获取调度程序,我会收到以下异常:
13:20:23,636 INFO [org.quartz.core.QuartzScheduler] (MSC service thread 1-15) Quartz Scheduler v.1.8.3 created.
13:20:23,646 INFO [org.quartz.impl.jdbcjobstore.JobStoreCMT] (MSC service thread 1-15) Using db table-based data access locking (synchronization).
13:20:23,682 INFO [org.quartz.impl.jdbcjobstore.JobStoreCMT] (MSC service thread 1-15) Removed 0 Volatile Trigger(s).
13:20:23,684 INFO [org.quartz.impl.jdbcjobstore.JobStoreCMT] (MSC service thread 1-15) Removed 0 Volatile Job(s).
13:20:23,687 INFO [org.quartz.core.QuartzScheduler] (MSC service thread 1-15) Scheduler MyScheduler_$_NON_CLUSTERED shutting down.
13:20:23,689 INFO [org.quartz.core.QuartzScheduler] (MSC service thread 1-15) Scheduler MyScheduler_$_NON_CLUSTERED paused.
13:20:23,691 INFO [org.quartz.core.QuartzScheduler] (MSC service thread 1-15) Scheduler MyScheduler_$_NON_CLUSTERED shutdown complete.
13:20:23,707 INFO [stdout] (MSC service thread 1-15) java.lang.reflect.UndeclaredThrowableException
13:20:23,709 INFO [stdout] (MSC service thread 1-15) at $Proxy33.rollback(Unknown Source)
13:20:23,710 INFO [stdout] (MSC service thread 1-15) at org.quartz.impl.jdbcjobstore.JobStoreSupport.rollbackConnection(JobStoreSupport.java:3604)
13:20:23,713 INFO [stdout] (MSC service thread 1-15) at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLock(JobStoreSupport.java:3776)
13:20:23,715 INFO [stdout] (MSC service thread 1-15) at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLock(JobStoreSupport.java:3725)
13:20:23,717 INFO [stdout] (MSC service thread 1-15) at org.quartz.impl.jdbcjobstore.JobStoreSupport.cleanVolatileTriggerAndJobs(JobStoreSupport.java:747)
13:20:23,719 INFO [stdout] (MSC service thread 1-15) at org.quartz.impl.jdbcjobstore.JobStoreSupport.initialize(JobStoreSupport.java:605)
13:20:23,721 INFO [stdout] (MSC service thread 1-15) at org.quartz.impl.jdbcjobstore.JobStoreCMT.initialize(JobStoreCMT.java:142)
13:20:23,723 INFO [stdout] (MSC service thread 1-15) at org.quartz.impl.StdSchedulerFactory.instantiate(StdSchedulerFactory.java:1269)
13:20:23,724 INFO [stdout] (MSC service thread 1-15) at org.quartz.impl.StdSchedulerFactory.getScheduler(StdSchedulerFactory.java:1460)
13:20:23,862 INFO [stdout] (MSC service thread 1-15) Caused by: java.lang.reflect.InvocationTargetException
13:20:23,865 INFO [stdout] (MSC service thread 1-15) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
13:20:23,866 INFO [stdout] (MSC service thread 1-15) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
13:20:23,868 INFO [stdout] (MSC service thread 1-15) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
13:20:23,869 INFO [stdout] (MSC service thread 1-15) at java.lang.reflect.Method.invoke(Method.java:597)
13:20:23,870 INFO [stdout] (MSC service thread 1-15) at org.quartz.impl.jdbcjobstore.AttributeRestoringConnectionInvocationHandler.invoke(AttributeRestoringConnectionInvocationHandler.java:71)
13:20:23,872 INFO [stdout] (MSC service thread 1-15) ... 85 more
13:20:23,873 INFO [stdout] (MSC service thread 1-15) Caused by: java.sql.SQLException: You cannot rollback during a managed transaction!
13:20:23,875 INFO [stdout] (MSC service thread 1-15) at org.jboss.jca.adapters.jdbc.BaseWrapperManagedConnection.jdbcRollback(BaseWrapperManagedConnection.java:1022)
13:20:23,876 INFO [stdout] (MSC service thread 1-15) at org.jboss.jca.adapters.jdbc.WrappedConnection.rollback(WrappedConnection.java:778)
13:20:23,878 INFO [stdout] (MSC service thread 1-15) ... 90 more
13:20:23,880 INFO [org.jboss.as] (MSC service thread 1-11) JBAS015951: Admin console listening on http://127.0.0.1:9990
如果我将集群属性设置为 true,我会得到:
13:29:31,562 INFO [org.quartz.core.QuartzScheduler] (MSC service thread 1-4) Scheduler meta-data: Quartz Scheduler (v1.8.3) 'ViSixdScheduler' with instanceId 'Se-PC1339507771533'
Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
NOT STARTED.
Currently in standby mode.
Number of jobs executed: 0
Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 25 threads.
Using job-store 'org.quartz.impl.jdbcjobstore.JobStoreCMT' - which supports persistence. and is clustered.
13:29:31,579 INFO [org.quartz.impl.StdSchedulerFactory] (MSC service thread 1-4) Quartz scheduler 'MyScheduler' initialized from default resource file in Quartz package: 'quartz.properties'
13:29:31,581 INFO [org.quartz.impl.StdSchedulerFactory] (MSC service thread 1-4) Quartz scheduler version: 1.8.3
13:29:33,577 INFO [org.quartz.utils.UpdateChecker] (Timer-1) New Quartz update(s) found: 1.8.5 [http://www.terracotta.org/kit/reflector?kitID=default&pageID=QuartzChangeLog]
13:29:43,970 INFO [org.quartz.impl.jdbcjobstore.JobStoreCMT] (MSC service thread 1-4) ClusterManager: detected 1 failed or restarted instances.
13:29:43,972 INFO [org.quartz.impl.jdbcjobstore.JobStoreCMT] (MSC service thread 1-4) ClusterManager: Scanning for instance "Se-PC1339504980109"'s failed in-progress jobs.
13:29:43,979 ERROR [org.quartz.impl.jdbcjobstore.JobStoreCMT] (MSC service thread 1-4) ClusterManager: Error managing cluster: null: java.lang.reflect.UndeclaredThrowableException
at $Proxy33.commit(Unknown Source) at org.quartz.impl.jdbcjobstore.JobStoreSupport.commitConnection(JobStoreSupport.java:3624) [quartz-1.8.3.jar:]
at org.quartz.impl.jdbcjobstore.JobStoreSupport.doCheckin(JobStoreSupport.java:3213) [quartz-1.8.3.jar:]
at org.quartz.impl.jdbcjobstore.JobStoreSupport$ClusterManager.manage(JobStoreSupport.java:3820) [quartz-1.8.3.jar:]
如果我不在调度程序上调用 start 我只能解雇工作 @once .... 但如果不启动它就毫无用处:(
任何帮助是极大的赞赏。
谢谢