quartz 定时调度持久化数据库配置文件
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 定时调度持久化数据库配置文件的更多相关文章
- java 多线程——quartz 定时调度的例子
java 多线程 目录: Java 多线程——基础知识 Java 多线程 —— synchronized关键字 java 多线程——一个定时调度的例子 java 多线程——quartz 定时调度的例子 ...
- Quartz定时调度框架
Quartz定时调度框架CronTrigger时间配置格式说明 CronTrigger时间格式配置说明 CronTrigger配置格式: 格式: [秒] [分] [小时] [日] [月] [周] [年 ...
- Spring Quartz定时调度任务配置
applicationContext-quartz.xml定时调度任务启动代码: <?xml version="1.0" encoding="UTF-8" ...
- ASP.NET Core使用Quartz定时调度
在应用程序开发过程中,经常会需要定时任务调度功能,本篇博客介绍Asp.net Core如何使用Quartz完成定时调度 一.Quartz使用步骤 创建调度器scheduler,并开启 创建Job作业 ...
- Quartz定时调度jar包的执行Demo分享
1.Quartz简介 Quartz框架的核心是调度器.调度器负责管理Quartz应用运行时环境.调度器不是靠自己做所有的工作,而是依赖框架内一些非常重要的部件.Quartz不仅仅是线程和线程管理. ...
- Quartz定时调度
测试类 import static org.quartz.JobBuilder.newJob; import static org.quartz.TriggerBuilder.newTrigger; ...
- Quartz定时调度在Web中的应用
1.在数据库中建一个job表和job日志表 job表
- Spring使用Quartz定时调度Job无法Autowired注入Service的解决方案
1)自定义JobFactory,通过spring的AutowireCapableBeanFactory进行注入,例如: public class MyJobFactory extends org.s ...
- Spring—Quartz定时调度CronTrigger时间配置格式的实例
格式说明:[秒] [分] [小时] [日] [月] [周] [年] 序号 说明 是否必填 允许填写的值 允许的通配符 1 秒 是 0-59 , - * / 2 分 是 0-59 , - * / 3 小 ...
随机推荐
- C语言入门(14)——结构体
整数.字符.布尔值.浮点数这些数据类型都具有单一的值,这些可称为基本数据类型.但字符串是一个例外,它由很多字符组成,像这种由基本类型组成的数据类型称为复合数据类型,正如表达式和语句有组合规则一样,由基 ...
- chrome 下的 proxy 插件安装
Install “Proxy SwitchyOmega” extensions for chrome.
- Cpp again
1,
- 04737_C++程序设计_第9章_运算符重载及流类库
例9.1 完整实现str类的例子. #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> ...
- C++结构体中sizeof
说明: 结构体的sizeof值,并不是简单的将其中各元素所占字节相加,而是要考虑到存储空间的字节对齐问题.这些问题在平时编程的时候也确实不怎么用到,但在一些笔试面试题目中出是常常出现,一.解释 现代计 ...
- leetcode Contains Duplicate python
Given an array of integers, find if the array contains any duplicates. Your function should return t ...
- Labview学习之程序Web发布
Labview学习之程序Web发布 1. LabVIEW Web服务器 在LabVIEW开发环境中,自身带了一个已连接好的Web服务器.LabVIEW Web服务器除了与其他Web服务器一样能 ...
- Jquery 获取IP地址
//获取ip和地址 $(function () { var url = 'http://chaxun.1616.net/s.php?type=ip&output=json&callba ...
- ThinkPHP第二十六天(JQuery操作select,SESSION和COOKIE)
1.JQuery操作select,假设<select id="my"> A:双击选项<option>事件,应该是select的dbclick事件. B:获得 ...
- Java文本编辑器中遇到的问题详解
今天介绍文件的读取和写入,分别用FileReader,FileWriter 1,FileWriter类(字符输出流类) 构造方法:FileWriter fw = new FileWriter(Stri ...