Reputation: 182
I am doing a web application, use Spring 3.0.5.RELEASE + quartz 1.8.6, and MySQL 5.5 is used to store the scheduling information. When I restart the tomcat, the quartz has been restarted, but it doesn't rerun jobs. For example, I have a job to print "aaa" 10 times, and I restarted the tomcat after it has run 3 times, the remaining 7 times will not be done. Below is the spring configure file, all the jobs and triggers will created by user, so there is only one bean.
<bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"
lazy-init="false"></bean>
Below is the quartz.properties.
org.quartz.scheduler.instanceName = DefaultQuartzScheduler
org.quartz.scheduler.rmi.export = false
org.quartz.scheduler.rmi.proxy = false
org.quartz.scheduler.wrapJobExecutionInUserTransaction = false
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 10
org.quartz.threadPool.threadPriority = 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.useProperties = false
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.jobStore.isClustered = false
# Configure Datasources
#============================================================================
org.quartz.jobStore.dataSource = myDS
org.quartz.dataSource.myDS.driver = com.mysql.jdbc.Driver
org.quartz.dataSource.myDS.URL = jdbc:mysql://localhost:3306/quartz1x?useUnicode=true&characterEncoding=utf8
org.quartz.dataSource.myDS.user = root
org.quartz.dataSource.myDS.password =111111
org.quartz.dataSource.myDS.maxConnections = 10
Spring indected the Scheduler, and below is the code
JobDetail jobDetail = new JobDetail("jName","gName", NewJob.class);
SimpleTrigger simpleTrigger = new SimpleTrigger("jName1","gName1");
simpleTrigger.setStartTime(new Date());
simpleTrigger.setRepeatInterval(3000);
simpleTrigger.setRepeatCount(10);
scheduler.scheduleJob(jobDetail, simpleTrigger);
NewJob.java
public class NewJob implements Job {
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
System.out.println(new Date());
}
}
If I don't use spring, but servlet(org.quartz.ee.servlet.QuartzInitializerServlet), there is no problem.
Upvotes: 1
Views: 1395
Reputation: 182
Spring does not read quartz.properties default, you should write the config file in the bean just like below.
<bean id="scheduler"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean"
lazy-init="false">
<property name="configLocation" value="classpath:quartz.properties" />
</bean>
Upvotes: 2