- 浏览: 525068 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
gaolegao2008:
如果报 is_volum 列名找不到之类的,我是从新部署了一个 ...
spring quartz 定时器报错 -
gaolegao2008:
部署到linux上时,还有一种情况就是mysql数据库区分大小 ...
spring quartz 定时器报错 -
qq123zhz:
yahier 写道 对我有帮助,但我看的一个demo程序,却没 ...
spring quartz 定时器报错 -
qq123zhz:
这个要在eclipse的插件环境下运行的,你不懂eclipse ...
GEF 自动布局 -
qq123zhz:
这个很久了,不记得啥时候写的了
json转为Map
很有用的quartz的学习资料。。。
本人最近也一值在项目是使用。。。。。
package com.chinaGPS.driverBook.service.impl; import java.text.ParseException; import java.util.ArrayList; import java.util.Collection; import java.util.List; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.SchedulerException; import org.springframework.context.support.FileSystemXmlApplicationContext; import org.springframework.scheduling.quartz.CronTriggerBean; import org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean; import com.chinaGPS.driverBook.dao.ScheduleDao; import com.chinaGPS.driverBook.pojo.ScheduleInfo; import com.chinaGPS.driverBook.service.IQuartzTaskService; import com.chinaGPS.driverBook.service.job.WeatherJob; /** * 定义任务调度 * * @author zhz * */ public class QuartzTaskService implements IQuartzTaskService { private static final String WEATHERJOBNAME = "weatherTrigger"; private static final String WEATHERGROUP = "weatherGroup"; private static final String WEATHERTARGETMETHOD = "saveCityWeather"; private static IQuartzTaskService manager; private Scheduler schedulerFactory; private WeatherJob weatherJob; private ScheduleDao scheduleDao; private CronTriggerBean trigger; private JobDetail weatherJobDetail; public ScheduleDao getScheduleDao() { return scheduleDao; } public void setScheduleDao(ScheduleDao scheduleDao) { this.scheduleDao = scheduleDao; } public WeatherJob getWeatherJob() { return weatherJob; } public void setWeatherJob(WeatherJob weatherJob) { this.weatherJob = weatherJob; } public Scheduler getSchedulerFactory() { return schedulerFactory; } public void setSchedulerFactory(Scheduler schedulerFactory) { this.schedulerFactory = schedulerFactory; } @Override public void reWeatherCatchScheduleJob() { try { // 运行时可通过动态注入的scheduler得到trigger List<ScheduleInfo> dbCronExpressionList = getCronExpressionFromDB(); //先清除trigger String [] triggesName = schedulerFactory.getTriggerNames(WEATHERGROUP); for (int i = 0; i < triggesName.length; i++) { String triggerName = triggesName[i]; schedulerFactory.unscheduleJob(triggerName, WEATHERGROUP); } if(schedulerFactory.getTriggerNames(WEATHERGROUP).length==0){ //然后暂停任务工厂 System.out.println("后台定时调度天气任务,重置。。。。。"); } for (ScheduleInfo info : dbCronExpressionList) { weatherJobDetail = new JobDetail(info.getId(), WEATHERGROUP, WeatherJob.class); trigger = new CronTriggerBean(); trigger.setName(info.getId()); // trigger.setJobDetail(weatherJobDetail); trigger.setGroup(WEATHERGROUP); trigger.setCronExpression(info.getJobCronExp()); schedulerFactory.scheduleJob(weatherJobDetail,trigger); } schedulerFactory.startDelayed(3); } catch (SchedulerException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } // 下面是具体的job内容,可自行设置 weatherJob.saveCityWeather(); // executeJobDetail(); } private List<ScheduleInfo> getCronExpressionFromDB() { return scheduleDao.findAll(); // return "0/10 * * * * ?"; } public static void main(String[] args) { Collection<String> files = new ArrayList<String>(); files.add("/WebContent/WEB-INF/spring/*.xml"); FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext( files.toArray(new String[0])); manager = (IQuartzTaskService) ctx.getBean("quartzTaskService"); manager.reWeatherCatchScheduleJob(); } }
以上是编程调用。。。。
<?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:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd" default-autowire="byName"> <!-- 每天晚上12点调度 三个任务 --> <bean id="sysPwdJob" class="com.chinaGPS.driverBook.service.job.SysPwdSuccessJob"> <property name="userManagerService" ref="userManagerService"></property> </bean> <bean id="servicePwdJob" class="com.chinaGPS.driverBook.service.job.ServicePwdFailResetJob"> <property name="userManagerService" ref="userManagerService"></property> </bean> <bean id="carBindJob" class="com.chinaGPS.driverBook.service.job.BindCarFailResetJob"></bean> <!-- 天气任务 --> <bean id="weatherJob" class="com.chinaGPS.driverBook.service.job.WeatherJob"></bean> <!-- 定时任务开始 --> <bean id="sysPwdJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject"> <ref bean="sysPwdJob"/> </property> <property name="targetMethod"> <value>resetCount</value> </property> </bean> <bean id="servicePwdJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject"> <ref bean="servicePwdJob"/> </property> <property name="targetMethod"> <value>resetCount</value> </property> </bean> <bean id="carBindJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject"> <ref bean="carBindJob"/> </property> <property name="targetMethod"> <value>resetCount</value> </property> </bean> <!-- 天气任务 保存json任务--> <bean id="weatherJobSaveDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject"> <ref bean="weatherJob"/> </property> <property name="targetMethod"> <value>saveCityWeather</value> </property> </bean> <!-- 天气任务 deletejson任务--> <!-- <bean id="weatherJobDeleteDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> --> <!-- <property name="targetObject"> --> <!-- <ref bean="weatherJob"/> --> <!-- </property> --> <!-- <property name="targetMethod"> --> <!-- <value>saveCityWeather</value> --> <!-- </property> --> <!-- </bean> --> <!-- 定义trigger --> <bean id="sysPwdTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <!-- 这里不可以直接在属性jobDetail中引用taskJob,因为他要求的是一个jobDetail类型的对象,所以我们得通过MethodInvokingJobDetailFactoryBean来转一下 --> <property name="jobDetail"> <ref bean="sysPwdJobDetail" /> </property> <!-- 每天凌晨12点执行一次 --> <property name="cronExpression"> <value>0 0 0 * * ?</value> </property> </bean> <bean id="servicePwdTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <!-- 这里不可以直接在属性jobDetail中引用taskJob,因为他要求的是一个jobDetail类型的对象,所以我们得通过MethodInvokingJobDetailFactoryBean来转一下 --> <property name="jobDetail"> <ref bean="servicePwdJobDetail" /> </property> <!-- 每天凌晨12点执行一次 --> <property name="cronExpression"> <value>0 0 0 * * ?</value> </property> </bean> <bean id="carBindTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <!-- 这里不可以直接在属性jobDetail中引用taskJob,因为他要求的是一个jobDetail类型的对象,所以我们得通过MethodInvokingJobDetailFactoryBean来转一下 --> <property name="jobDetail"> <ref bean="carBindJobDetail" /> </property> <!-- 每天凌晨12点执行一次 --> <property name="cronExpression"> <value>0 0 0 * * ?</value> </property> </bean> <!-- 天气json定时 触发--> <bean id="weatherTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail"> <ref bean="weatherJobSaveDetail"/> </property> <property name="cronExpression"> <value>0 0 0 * * ?</value> </property> </bean> <!-- 触发器工厂,将所有的定时任务都注入工厂--> <bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" autowire="no" lazy-init="false"> <!-- 添加触发器 --> <property name="triggers"> <list> <!-- 将上面定义的测试定时任务注入(可以定义多个定时任务,同时注入)--> <ref local="sysPwdTrigger" /> <ref local="servicePwdTrigger" /> <ref local="carBindTrigger" /> <ref local="weatherTrigger"/> </list> </property> </bean> <!-- 定时任务 结束 --> <bean id="quartzTaskService" class="com.chinaGPS.driverBook.service.impl.QuartzTaskService" scope="prototype"> <property name="schedulerFactory" ref="schedulerFactory"></property> <property name="scheduleDao" ref="scheduleDao"></property> </bean> </beans>
以上是spring 配置调用。。。。。。。。。。。
编程调用时,可以对某个任务设置多个触发时间任务,任务执行的规则来自数据库。。。。。。。。
xml配置就很难做到这一点。。。。。。
- Quartz_Job.rar (1.2 MB)
- 下载次数: 19
- Quartz_API_1.65.zip (1011.3 KB)
- 下载次数: 19
发表评论
-
eclipse Resource 资料
2016-11-15 16:51 578IWorkspace/IWorkspaceRoot/IPro ... -
.docker/machine/machines/default/ca.pem: no such file or directory
2016-09-06 15:59 841Was doing adocker-machine env ... -
list.AddAll 去重复
2015-09-11 12:01 5846问题描述: 有List A和B,A、B中元素都是可保证 ... -
eclipse 插件开发 Setting the Java build path
2014-06-04 11:00 1175JDT Plug-in Developer Guide & ... -
xstream 下划线_问题
2013-12-30 10:18 4139最近在使用xtream 1.4.3,出现了如下的问题: ... -
RCP MessageConsole设置显示的最大行数
2013-09-05 11:34 899MessageConsole.setWaterMarks(5 ... -
freemarker 自定义freeMarker标签
2013-08-12 16:09 3849import java.io.IOException; i ... -
xstream javabean设置属性默认值的问题
2013-04-24 09:54 6524在xstream反序列化使用过程中发现,如果xml无该属 ... -
在使用xstream反序列化时遇到的问题
2013-04-24 09:42 1711public abstract class SBase { ... -
RCP 知识点
2013-03-14 15:10 928获得工作区的所有工程: //获得workspace的所有 ... -
RCP FileSystem 文件系统
2013-02-19 10:42 1333public static File toLocalFile ... -
json转为Map
2013-01-19 22:27 32762package digu.pendant.util; ... -
eclipse4.x 去掉quick access
2013-01-11 14:57 3990/** * 去掉quick access * ... -
xstream 的高级用法,自定义输出结构
2012-12-19 14:35 2366public static void main(Stri ... -
jdt 核心知识
2012-11-27 21:39 1185jdt官方核心知识...................... ... -
jdt 创建java工程,生成代码,运行main方法
2012-11-27 10:50 2288public static IJavaProje ... -
两个osgi的例子程序
2012-11-20 10:21 1007osgi的例子....................直接上代 ... -
jfreechart 的官方例子,很全
2012-11-20 10:19 904jfreechart的官方的demon,很全。 -
SWT 隔行换色-自动宽高调整
2012-10-16 17:32 1666** * 创建:ZhengXi 2009-8-4 */ ... -
RCP 为action添加操作进度条
2012-10-16 13:59 1249public class StartAction extend ...
相关推荐
基于web开发的quartz定时任务调度整合配置源码....
spring整合quartz定时任务调度..........
Spring Quartz 定时调度任务,带中文注解与jar文件,导入项目即可直接运行。
2、JobDetail是一个可执行的工作,它本身可能是有状态的 3、Trigger触发器代表一个调度参数的配置,什么时候去调 4、当JobDetail和Trig
Java使用quartz实现任务调度定时任务
Quartz.net作业调度自定义定时执行任务多任务执行c#,定时执行任务,如超时取消订单,自动确认收货等等
定时任务quartz实现分组串行并行动态配置
Spring中集成的一个定时任务调度器,以备以后使用
quartz.net+TopShelf
springmvc中实现quartz定时任务(每分钟的第3秒执行任务调度方法)文章支持jar包
SpringBoot整合Quartz任务定时调度,可以参考我的博客进行学习https://blog.csdn.net/sujin_/article/details/80615823
该jar是使用分布式定时任务或者quartz任务调度框架技术所需的jar包
1、若是部署多台机器,到了时间点,只有一台会执行,其他不会执行。 2、若多个节点其中一个scheduler执行job失败,将会被另外一个scheduler执行
Quartz.net做为任务调度核心,利用Log4Net做为日志输出,C#完成WINDOWS服务在后台定时执行任务;
基于quartz的任务调度插件,引入到spring项目即可使用,依赖于redis的订阅可以对任务立即运行,修改任务自动执行时间/频率,暂停等操作。适合需要定时任务的项目进行快速的集成开发,提高开发效率,降低开发难度。
使用Quartz调度任务,根据需要人为的终止某个任务,适用于很多常见的场景
Quartz任务调度器与spring整合,做项目的时候常听测试说谁在起着quartz,也不知道是啥,问了下同事,就是定时去执行某些任务的,刚好bug比较少,学习了一下~