spring Quartz定时任务
来源:互联网 发布:淘宝网电脑版登录 怎么 编辑:程序博客网 时间:2024/04/24 22:33
不多说直接上代码
用的maven管理哈哈
<dependency><groupId>org.quartz-scheduler</groupId><artifactId>quartz</artifactId><version>1.8.5</version></dependency>
首先是配置文件
<?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"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"><bean id="reloadTask" class="com.demo.schedule.SchedulerTask"init-method="initial"></bean><bean id="jobDetail-reload"class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"><property name="targetObject"><ref bean="reloadTask" /></property><property name="targetMethod"><value>reload</value></property></bean><bean id="trigger-reload"class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"><property name="jobDetail"><ref bean="jobDetail-reload" /></property><property name="cronExpression"><value>0 0 0 * * ? </value></property></bean><bean id="registerQuartz"class="org.springframework.scheduling.quartz.SchedulerFactoryBean"><property name="triggers"><list><ref bean="trigger-reload" /></list></property></bean></beans>
定时任务类
package com.demo.schedule;import java.text.ParseException;import org.quartz.CronTrigger;import org.quartz.Scheduler;import org.quartz.SchedulerException;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.factory.annotation.Qualifier;public class SchedulerTask {@Autowired@Qualifier("trigger-reload")private CronTrigger cronTrigger;@Autowired@Qualifier("registerQuartz")private Scheduler scheduler;public void initial() throws ParseException, SchedulerException {checkScheduleTime();}private void checkScheduleTime() throws ParseException, SchedulerException { // 5秒一次String scheduleTime = "0/5 * * * * ?";if (scheduleTime != null) {String oriCronExpression = cronTrigger.getCronExpression();if (!oriCronExpression.equals(scheduleTime)) {cronTrigger.setCronExpression(scheduleTime);scheduler.rescheduleJob("trigger-reload", Scheduler.DEFAULT_GROUP, cronTrigger);}}}public static int ORIGINAL_VERSION = 0;public void reload() throws Exception {int versionId = 0; // 可以从数据库取版本号比对更新,对吧 嘿嘿。。if (ORIGINAL_VERSION == versionId) {ORIGINAL_VERSION = versionId;System.out.println("start ==============...");}}}
ok 完事 复制到工程中绝对好使 。。。。。。。。。。。。。。。。。。。。。。。。
1 0
- Spring+Quartz定时任务
- spring quartz 定时任务
- Spring-quartz定时任务
- spring 定时任务 quartz
- spring quartz 定时任务
- spring Quartz 定时任务
- spring+quartz定时任务
- Spring Quartz 定时任务
- spring quartz 定时任务
- Spring+quartz 定时任务
- spring quartz定时任务
- spring-quartz 定时任务
- spring quartz 定时任务
- Spring-quartz定时任务
- Quartz Spring 定时任务
- Spring 定时任务--quartz
- spring定时任务quartz
- Spring Quartz定时任务
- Android 自定义view 随着刷新次数变多而变慢
- JavaWeb——MyBatis入门程序
- 欢迎使用CSDN-markdown编辑器
- 计算机中正数和负数原码、反码、补码的表示
- openCV下载地址
- spring Quartz定时任务
- Greenplum full backup
- 学习SpringMVC
- hibernate延时加载
- TCP三次握手原理详解
- 合并两个排序链表
- Android中Bundle类的作用
- 字符串替换
- 没必要参加嵌入式开发培训班 (学习嵌入式的资料)