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 小 ...
随机推荐
- Unix/Linux环境C编程入门教程(17) Gentoo LinuxCCPP开发环境搭建
1. Gentoo Linux是一套通用的.快捷的.完全免费的Linux发行,它面向开发人员和网络职业人员.与其他发行不同的是,Gentoo Linux拥有一套先进的包管理系统叫作Portage.在B ...
- opennebula kvm attach disk
openNebula hotPlug disk or nic 网络检索关键字(Network search keywords) 208.117.233.122 virsh attach disk vi ...
- Largest Rectangle in a Histogram(最大矩形面积,动态规划思想)
Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HP DL360 G7通过iLO部署系统
HPDL360 G7通过iLO部署系统 HP DL360 G7是没有光驱的服务器,可使用USB外置光驱.PXE网络安装.ILO方式的安装操作系统 一.HP iLO 简介 iLO 是一组芯片,内部是vx ...
- android UI-EditText的长度监听慎用TextWatcher
在用户昵称的输入时,限定8个字符,本意是在输入超过8个时候,页面toast一个提示,就是下面的TextWatcher的监听,在afterTextChanged中处理. 原bug:huawei MT2- ...
- 单选,复选操作div,显示隐藏
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8& ...
- BZOJ 2300: [HAOI2011]防线修建( 动态凸包 )
离线然后倒着做就变成了支持加点的动态凸包...用平衡树维护上凸壳...时间复杂度O(NlogN) --------------------------------------------------- ...
- adb wifi连接手机
1. 默认情况下,ADB是通过USB来进行连接的. 不需要USB线,直接在android设备上安装一个超级终端,在终端里运行以下代码即可: su setprop service.adb.tcp.por ...
- mongodb数据库调试问题:‘db object already connecting, open cannot be called multiple times’
在微博小系统的调试过程中: (1)登入登出可以正常显示,就是在注册的时候网络连接突然停止,但是用户名和密码已经存入数据库中,报错为:undefined is not a function 错误主要指向 ...
- HortonWorks
http://zh.hortonworks.com/products/hortonworks-sandbox/