- If you're using JDBC-Jobstore, you will need a DataSource for its use.
- It is recommended that your DataSource max connection size be configured to be at least the number of worker threads in the thread pool plus three.
│ pom.xml │ └─src └─main ├─java │ └─cn │ └─zno │ └─job │ Breathe.java │ Main.java │ └─resources Beans-Quartz.xml db.properties quartz.properties tables_oracle.sql
项目地址:https://github.com/witaste/quartz.git
所需依赖:
<dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.1.6.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>4.1.6.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>4.1.6.RELEASE</version> </dependency> <!-- 定时任务 --> <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz</artifactId> <version>2.2.2</version> </dependency> <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz-jobs</artifactId> <version>2.2.2</version> </dependency> <!-- ojdbc6 --> <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc6</artifactId> <version>11.2.0.3.0</version> </dependency> <!-- dbcp2 --> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-dbcp2</artifactId> <version>2.1.1</version> </dependency> </dependencies>
Beans-Quartz.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:task="http://www.springframework.org/schema/task" xmlns:context="http://www.springframework.org/schema/context" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd"> <task:executor id="threadPoolTaskExecutor" pool-size="1" /> <util:properties id="config" location="classpath:db.properties" /> <bean id="dataSourceAlpha" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="#{config['jdbc.driverClassName']}" /> <property name="url" value="#{config['jdbc.url']}" /> <property name="username" value="#{config['jdbc.username']}" /> <property name="password" value="#{config['jdbc.password']}" /> <property name="defaultAutoCommit" value="true" /> </bean> <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="jobFactory"> <bean class="org.springframework.scheduling.quartz.SpringBeanJobFactory" /> </property> <property name="dataSource" ref="dataSourceAlpha" /> <property name="configLocation" value="classpath:quartz.properties" /> <property name="applicationContextSchedulerContextKey" value="applicationContextKey" /> <property name="startupDelay" value="0" /> <property name="overwriteExistingJobs" value="true" /> <property name="exposeSchedulerInRepository" value="true" /> <property name="taskExecutor" ref="threadPoolTaskExecutor" /> <property name="triggers"> <list> <ref bean="cronTrigger_1" /> </list> </property> </bean> <bean id="cronTrigger_1" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> <property name="jobDetail" ref="jobDetail_1" /> <property name="cronExpression" value="* * * * * ?" /> </bean> <bean id="jobDetail_1" class="org.springframework.scheduling.quartz.JobDetailFactoryBean"> <property name="jobClass" value="cn.zno.job.Breathe" /> </bean> <bean id="breath" class="cn.zno.job.Breathe" /> </beans>
quartz.properties
#============================================================================ # Configure Main Scheduler Properties #============================================================================ org.quartz.scheduler.instanceName = QuartzScheduler org.quartz.scheduler.instanceId = AUTO org.quartz.scheduler.skipUpdateCheck=true #============================================================================ # Configure JobStore #============================================================================ org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.oracle.OracleDelegate org.quartz.jobStore.tablePrefix = QSMSE_
tables_oracle.sql
建好表
注意以下建议:
连接池的连接数 = threadPoolTaskExecutor + 3