使用Quartz调度器运行多个作业失败,需对下述代码做哪些修改?
Let's break down the critical adjustments you need to make to your Quartz setup to resolve failures when running multiple jobs in a clustered environment:
1. Fix the Driver Delegate Class Name
Your current driverDelegateClass has an extra trailing space, which will cause a class loading error. Remove that space immediately:
<prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.oracle.OracleDelegate</prop>
2. Add a Consistent Scheduler Instance Name
Clustered Quartz nodes must share the same instance name to recognize each other as part of the same cluster. You're missing this key property—add it:
<prop key="org.quartz.scheduler.instanceName">MyClusteredQuartzScheduler</prop>
Keep this value identical across all nodes in your cluster.
3. Configure Cluster Check-In Interval
Without this property, cluster nodes won't sync their status regularly, leading to job misfires, duplicate executions, or failures. Add a reasonable interval (15 seconds is a safe default):
<prop key="org.quartz.jobStore.clusterCheckinInterval">15000</prop>
4. Add Thread Pool Configuration (Critical for Multi-Job Support)
You didn't include thread pool settings, but running multiple jobs requires enough threads to handle concurrent executions. Add these properties to avoid thread starvation:
<prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop> <prop key="org.quartz.threadPool.threadCount">10</prop> <!-- Adjust based on your job load --> <prop key="org.quartz.threadPool.threadPriority">5</prop>
Tweak threadCount based on how many concurrent jobs you expect to run.
5. Re-evaluate JobStore Type (If Using Container-Managed Transactions)
You're using JobStoreTX, which requires Quartz to manage its own transactions. If your application runs in an app server with container-managed transactions (like Spring), switch to JobStoreCMT instead:
<prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreCMT</prop>
This ensures transactions align with your application's transaction management, preventing data inconsistencies that cause job failures.
Bonus: Validate Database Setup
Double-check that you've created all required Quartz tables for Oracle (using the tables_oracle.sql script from Quartz's distribution) and that the database user has full read/write permissions on these tables. Missing or misconfigured tables are a common hidden cause of multi-job failures.
内容的提问来源于stack exchange,提问作者Divya Murugan

