-
1. Re: using components.xml to schedule Quartz job in cluster
mpopetz Mar 21, 2008 4:19 PM (in response to admin.admin.email.tld)We handle this manually in our 12 node cluster. ie: Each node has a servername passed in at startup via the -D flag and then we use that name plus name of the task to query the database to see if the job should be running on that node.
It would be nice if there were a built in way to handle this, but I haven't seen one yet.
Some code to illustrate in case my description wasn't clear. The SiteGlobal entity is a name/value pair we store in the db for config.
SiteGlobal globalValue = SiteGlobal.retrieveByName(discussionSession, (serverName==null?"":serverName+ ".QUARTZ_ENABLED")); if(globalValue==null) { System.out.println("Quartz not approved in the SiteGlobal table to run: siteGlobal: "+serverName+ ".QUARTZ_ENABLED"); enabled = false; } else { enabled = globalValue.getValue().equalsIgnoreCase("ON"); } if (enabled) { apacheLogFollower.lookForNewData(5000L, 60000L);
-
2. Re: using components.xml to schedule Quartz job in cluster
marius.oancea Mar 13, 2009 11:11 AM (in response to admin.admin.email.tld)I think this is not the idea of clustering. All the nodes has to have the chance to run the job.
I have a similar architecture:
@Observer("org.jboss.seam.postInitialization")
public String callScheduler() {
...
QuartzTriggerHandle handleHour = processor.scheduleCollector(new Date(), "0 0/30 * * * ?");
}
and:
@Asynchronous
@Transactional
public QuartzTriggerHandle scheduleCollector
(@Expiration Date when, @IntervalCron String cron) {
// do something at the scheduled time
}
My seam.quartz.property is:
#============================================================================
# Configure Main Scheduler Properties
#============================================================================
org.quartz.scheduler.instanceName = DefaultQuartzScheduler
org.quartz.scheduler.instanceId = AUTO
org.quartz.scheduler.rmi.export = false
org.quartz.scheduler.rmi.proxy = false
org.quartz.scheduler.wrapJobExecutionInUserTransaction = false
#============================================================================
# Configure ThreadPool
#============================================================================
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 10
org.quartz.threadPool.threadPriority = 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true
#============================================================================
# Configure JobStore
#============================================================================
org.quartz.jobStore.misfireThreshold = 60000
org.quartz.jobStore.isClustered = true
org.quartz.jobStore.clusterCheckinInterval = 15000
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.DB2v8Delegate
org.quartz.jobStore.dataSource = QUARTZ
org.quartz.jobStore.nonManagedTXDataSource = QUARTZ_NO_TX
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.jobStore.selectWithLockSQL=SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ? FOR UPDATE
org.quartz.dataSource.QUARTZ.jndiURL = java:/emailcollectorDatasource
org.quartz.dataSource.QUARTZ_NO_TX.jndiURL = java:/emailcollectorDatasource
There is no classpath problem on seam2.1.1 but the jobs are executed on all the nodes of the cluster.
Any idea why? -
3. Re: using components.xml to schedule Quartz job in cluster
kapitanpetko Mar 13, 2009 12:38 PM (in response to admin.admin.email.tld)
Marius Oancea wrote on Mar 13, 2009 11:11:@Observer("org.jboss.seam.postInitialization") public String callScheduler() { ... QuartzTriggerHandle handleHour = processor.scheduleCollector(new Date(), "0 0/30 * * * ?"); }
There is no classpath problem on seam2.1.1 but the jobs are executed on all the nodes of the cluster.
Any idea why?'postInitialization' is raised for each app instance (at each node), so your job is probably scheduled multiple times. You will have to add some code to check if the job is already scheduled and skip scheduleCollector() if
it is. You will have to use the Quartz API for that (Scheduler, Trigger and friends).Btw, I recommend using the Quartz API directly for scheduling as well, especially since you are running in a
cluster. QuartzTriggerHandle is practically useless: there is no way to get the job/trigger name, you get automatically generated names (UIDs) that make debugging/support quite hard, etc. In short, the native Quartz
API is way more flexible. Seam Quartz wrappers work well for one shot jobs (async methods and stuff) but for anything more than that you are better off with native Quartz.