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);
} }
}

  

  

  

quartz 定时调度持久化数据库配置文件的更多相关文章

  1. java 多线程——quartz 定时调度的例子

    java 多线程 目录: Java 多线程——基础知识 Java 多线程 —— synchronized关键字 java 多线程——一个定时调度的例子 java 多线程——quartz 定时调度的例子 ...

  2. Quartz定时调度框架

    Quartz定时调度框架CronTrigger时间配置格式说明 CronTrigger时间格式配置说明 CronTrigger配置格式: 格式: [秒] [分] [小时] [日] [月] [周] [年 ...

  3. Spring Quartz定时调度任务配置

    applicationContext-quartz.xml定时调度任务启动代码: <?xml version="1.0" encoding="UTF-8" ...

  4. ASP.NET Core使用Quartz定时调度

    在应用程序开发过程中,经常会需要定时任务调度功能,本篇博客介绍Asp.net Core如何使用Quartz完成定时调度 一.Quartz使用步骤 创建调度器scheduler,并开启 创建Job作业 ...

  5. Quartz定时调度jar包的执行Demo分享

    1.Quartz简介 ​ Quartz框架的核心是调度器.调度器负责管理Quartz应用运行时环境.调度器不是靠自己做所有的工作,而是依赖框架内一些非常重要的部件.Quartz不仅仅是线程和线程管理. ...

  6. Quartz定时调度

    测试类 import static org.quartz.JobBuilder.newJob; import static org.quartz.TriggerBuilder.newTrigger; ...

  7. Quartz定时调度在Web中的应用

    1.在数据库中建一个job表和job日志表 job表

  8. Spring使用Quartz定时调度Job无法Autowired注入Service的解决方案

    1)自定义JobFactory,通过spring的AutowireCapableBeanFactory进行注入,例如: public class MyJobFactory extends  org.s ...

  9. Spring—Quartz定时调度CronTrigger时间配置格式的实例

    格式说明:[秒] [分] [小时] [日] [月] [周] [年] 序号 说明 是否必填 允许填写的值 允许的通配符 1 秒 是 0-59 , - * / 2 分 是 0-59 , - * / 3 小 ...

随机推荐

  1. js类方法,对象方法,原型的理解(转)

    function People(name) { this.name=name; //对象方法 this.Introduce=function(){ alert("My name is &qu ...

  2. ubuntu 安装mysql, 以及全然又一次安装的方法

    sudo apt-get install mysql-server 装完后 是无法远程訪问的. 要先改动 sudo vim /etc/mysql/my.cnf 找到 bind-address = 12 ...

  3. Android文件存储使用参考

    可能遇到的问题 android系统自身自带有存储,另外也可以通过sd卡来扩充存储空间.前者好比pc中的硬盘,后者好移动硬盘. 前者空间较小,后者空间大,但后者不一定可用. 开发应用,处理本地数据存取时 ...

  4. 简单C#文字转语音

    跟着微软走妥妥的,C#文字转语音有很多参数我就不说了,毕竟我也是初学者.跟大家分享最简单的方法,要好的效果得自己琢磨喽: 先添加引用System.Speech程序集: using System; us ...

  5. swipe.js文档及用法

    最近的一个项目中使用到了swipe.js这个插件 感觉非常的好用的 官方网站 http://swipejs.com/ https://github.com/bradbirdsall/Swipe 简介 ...

  6. Java String.indexOf() 函数用法小结

    1. indexOf的参数是 String,  startIndex: Number; indexOf的返回值为int, 2. Function indexOf 包含如下几个格式:1). Strng. ...

  7. pl sql项目演练--B2C商城项目

    项目学习视频下载地址:点击下载   1.注册会员及找回密码模块 }该模块主要功能有注册会员和找回密码 }注册会员:所需信息主要有:登录号.密码.真实姓名.性别.密码问题.密码答案.Email.地址.电 ...

  8. C++_前置声明

    为什么要有前置声明? eg: -定义一个类 class A,这个类里面使用了类B的对象b,然后定义了一个类B,里面也包含了一个类A的对象a,就成了这样: //a.h #include "b. ...

  9. istringstream和ostringstream的使用方法

    写程序用到istringstream和ostringstream,看了别人的博文,借鉴~~~~~~. iostream 标准库支持内存中的输入/输出,只要将流与存储在程序内存中的 string 对象捆 ...

  10. symfony2 关于是否需要建立多bundle

    http://blog.danielribeiro.org/yes-you-can-have-low-coupling-in-a-symfony-standard-edition-applicatio ...