1 下载quartz对应版本jar包

2 初始化对应数据库sql(版本需要对应,不然会出现少字段的情况) ,下载地址  https://github.com/quartz-scheduler/quartz/tree/quartz-1.8.x/docs/dbTables

讲sql在数据库中执行,12张表。 其余版本自己在git找。

3.配置文件  quartz.properties这个要配,不然会加载jar包中默认的quartz.properties文件。路径视情况而定,一般配置在classpath下;

#Created by xiaoshuai
#2016-6-2 10:37:35
#============================================================================
# Configure JobStore
#============================================================================
org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.isClustered=true
org.quartz.jobStore.maxMisfiresToHandleAtATime=1
org.quartz.jobStore.misfireThreshold=60000
org.quartz.jobStore.tablePrefix=T_SCS_QRTZ_ #============================================================================
# Configure Main Scheduler Properties
#============================================================================
org.quartz.scheduler.instanceName=scsSchedule
org.quartz.scheduler.instanceId=AUTO
org.quartz.scheduler.rmi.export=false
org.quartz.scheduler.rmi.proxy=false
org.quartz.scheduler.wrapJobExecutionInUserTransaction=false
org.quartz.scheduler.interruptJobsOnShutdown=true
org.quartz.scheduler.interruptJobsOnShutdownWithWait=true #============================================================================
# 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

4.因与spring集成,beans配置文件

<!-- JOBdetail -->
<bean id="opSelfcabStationJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="name">
<value>opSelfcabStationJob</value>
</property>
<property name="jobClass">
<value>cn..scsjob.scheduler.quartz.OpSelfcabStationJob</value>
</property>
<property name="jobDataAsMap">
<map>
<entry key="jobName">
<value>opSelfcabStationJob</value>
</entry>
<entry key="jobDesc">
<value>opSelfcabStationJob</value>
</entry>
</map>
</property>
</bean>
<!-- ======================== 调度触发器 ======================== -->
<bean id="CronTriggerBean" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="opSelfcabStationJob"></property>
<property name="cronExpression" value="0/30 * * * * ?"></property>
</bean> <!-- ======================== 调度工厂 ======================== -->
<bean id="SpringJobSchedulerFactoryBean" class="cn..scsjob.scheduler.quartz.task.ScsInitSchedulerFactoryBean"
lazy-init="false" autowire="no" destroy-method="destroy">
<property name="configLocation" value="classpath:quartz.properties" />
<property name="dataSource"> <ref bean="core_oracle_ds_rw" /> </property>
<property name="applicationContextSchedulerContextKey" value="applicationContext" />
<!-- 延时启动,应用先启动,scheduler在90s后执行-->
<property name="startupDelay" value="90"/>
<property name="triggers">
<list>
<ref bean="CronTriggerBean"/>
</list>
</property>
</bean>

5.java代码

executeInternal()方法执行前后可以做些日志记录工作
public abstract class ScsBaseJob extends QuartzJobBean{
protected final Logger logger = LoggerFactory.getLogger(getClass()); @Override
protected void executeInternal(JobExecutionContext context)
throws JobExecutionException {
logger.info("ScsBaseJob执行 executeInternal() ,Job Start Time : " + new Date());
this.doExecuteInternal(context);
logger.info("ScsBaseJob执行 executeInternal() ,Job End Time : " + new Date());
}
/**
*
* 业务执行方法
* @param context
*/
protected abstract void doExecuteInternal(JobExecutionContext context);
}

 具体的业务执行方法job:

public class OpJob extends ScsBaseJob {
@Override
protected void doExecuteInternal(JobExecutionContext context) {
System.out.println("OpSelfcabStationJob.doExecuteInternal()业务方法正在执行+++++++++++++++********************+++++++++++++++******************");
} }

  

 SchedulerFactoryBean:

public class ScsInitSchedulerFactoryBean extends SchedulerFactoryBean{
protected final Logger logger = LoggerFactory.getLogger(getClass()); public void destroy() {
logger.info("destroy quartz schedule..."); try {
this.getScheduler().shutdown();
super.destroy();
} catch (SchedulerException e) {
logger.error(e.getMessage(), e);
} }
}

  

  

  

最新文章

  1. Mysql的基础使用之MariaDB安装
  2. 网站标题ico那些事
  3. Java---网络蜘蛛-网页邮箱抓取器~源码
  4. matplotlib curve.py
  5. win7启动后报丢失nscmk.dll解决解决方式
  6. JSP页面中包含文件
  7. (大数据工程师学习路径)第一步 Linux 基础入门----文件系统操作与磁盘管理
  8. PHP中file_exists与is_file、is_dir的区别,以及执行效率的比较 转自#冰雪傲骨#
  9. Ceph部署(二)RGW搭建
  10. Python冒泡算法和修改配置文件
  11. input file 上传图片问题
  12. Markdown语法指南
  13. ComboBox下拉列表框
  14. php 从2维数组组合为四维数组分析(项目中前台侧边栏导航三级分类显示)
  15. 解决IIS7虚拟目录出现HTTP 错误 500.19(由于权限不足而无法读取配置文件)的问题
  16. Git GUI可视化操作教程
  17. 【学习笔记】python2和python3的input()
  18. Linux设备驱动剖析之SPI(四)
  19. 02: vue.js常用指令
  20. UVa 10048 噪音恐惧症(Floyd)

热门文章

  1. hdu 2102 A计划(双层BFS)(具体解释)
  2. 轻轻谈一下seaJs——模块化开发的利器
  3. HTML5阴影与渐变
  4. getMetaData()
  5. SSH框架的简化
  6. poj1006---中国剩余定理
  7. ping时不知道ping那个Ip的解决办法
  8. Spark学习之RDD的理解
  9. [转载]标签a的href和onclick
  10. gmpy2安装使用方法