quartz+spring 实现多任务动态定时器问题
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" 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/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springmodules.org/schema/ehcache http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd"> <!-- The Task Bean-->
<bean id="myTask" class="com.xxx.example.dynamicjob.MyTask" /> <!-- The quartz scheduler configuration -->
<bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"/> </beans>
package com.xxx.example.dynamicjob;
public class MyTask
{
public void performAction() {
System.out.println("Hey, you reached me...:)");
}
}
package com.xxx.example.dynamicjob;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.scheduling.quartz.CronTriggerBean;
import org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean; public class DynamicJobExample { /**
* @param args
*/
public static void main(String[] args) { ClassPathResource res = new ClassPathResource("dynamic-jobs.xml");
XmlBeanFactory factory = new XmlBeanFactory(res); //get the quartzFactory bean
Scheduler scheduler = (Scheduler) factory.getBean("scheduler"); //get the task bean
MyTask myTask = (MyTask) factory.getBean("myTask"); try {
// create JOB
MethodInvokingJobDetailFactoryBean jobDetail = new MethodInvokingJobDetailFactoryBean();
jobDetail.setTargetObject(myTask);
jobDetail.setTargetMethod("performAction");
jobDetail.setName("MyJobDetail");
jobDetail.setConcurrent(false);
jobDetail.afterPropertiesSet(); /* SimpleTriggerBean trigger = new SimpleTriggerBean();
trigger.setBeanName("MyTrigger");
trigger.setJobDetail((JobDetail) jobDetail.getObject());
trigger.setRepeatInterval(5000);
trigger.afterPropertiesSet();
*/ // create CRON Trigger
CronTriggerBean cronTrigger = new CronTriggerBean();
cronTrigger.setBeanName("CRON0001"); // Execute after each 5 second
String expression = "5 * * * * ?";
cronTrigger.setCronExpression(expression);
cronTrigger.afterPropertiesSet(); //scheduler.scheduleJob(jobDetail, cronTrigger); scheduler.scheduleJob((JobDetail) jobDetail.getObject(), cronTrigger); // Start Scheduler
scheduler.start(); } catch (Exception e) {
e.printStackTrace();
}
}
}
quartz+spring 实现多任务动态定时器问题的更多相关文章
- spring与quartz整合实现分布式动态创建,删除,改变执行时间定时任务(mysql数据库)
背景:因为在项目中用到了定时任务,当时想到了spring的quartz,写完发现费了很大功夫,光是整合就花了一上午,其中最大的问题就是版本问题,项目中用的是spring3.2.8的版本,查阅发现,3. ...
- Quartz 在 Spring 中如何动态配置时间--转
原文地址:http://www.iteye.com/topic/399980 在项目中有一个需求,需要灵活配置调度任务时间,并能自由启动或停止调度. 有关调度的实现我就第一就想到了Quartz这个开源 ...
- 如何通过Spring Boot配置动态数据源访问多个数据库
之前写过一篇博客<Spring+Mybatis+Mysql搭建分布式数据库访问框架>描述如何通过Spring+Mybatis配置动态数据源访问多个数据库.但是之前的方案有一些限制(原博客中 ...
- Spring框架中的定时器 使用和配置
Spring框架中的定时器 如何使用和配置 转载自:<Spring框架中的定时器 如何使用和配置>https://www.cnblogs.com/longqingyang/p/554543 ...
- Quartz Spring分布式集群搭建Demo
注:关于单节点的Quartz使用在这里不做详细介绍,直接进阶为分布式集群版的 1.准备工作: 使用环境Spring4.3.5,Quartz2.2.3,持久化框架JDBCTemplate pom文件如下 ...
- 在Spring中使用JDK定时器实现调度任务
在Spring中使用JDK定时器实现调度任务 作者:chszs,转载需注明.博客主页: http://blog.csdn.net/chszs 本文探讨Spring如何集成JDK的Timer定时器,实现 ...
- spring security实现动态配置url权限的两种方法
缘起 标准的RABC, 权限需要支持动态配置,spring security默认是在代码里约定好权限,真实的业务场景通常需要可以支持动态配置角色访问权限,即在运行时去配置url对应的访问角色. 基于s ...
- Spring Boot 2 (二):Spring Boot 2 动态 Banner
Spring Boot 2 (二):Spring Boot 2 动态 Banner Spring Boot 2.0 提供了很多新特性,其中就有一个小彩蛋:动态 Banner. 一.配置依赖 使用 Sp ...
- Spring AOP --JDK动态代理方式
我们知道Spring是通过JDK或者CGLib实现动态代理的,今天我们讨论一下JDK实现动态代理的原理. 一.简述 Spring在解析Bean的定义之后会将Bean的定义生成一个BeanDefinit ...
随机推荐
- ZOJ 3201 Tree of Tree
树形DP.... Tree of Tree Time Limit: 1 Second Memory Limit: 32768 KB You're given a tree with weig ...
- PHP跳转页面的几种实现方法详解
•PHP页面跳转一.header()函数header()函数是PHP中进行页面跳转的一种十分简单的方法.header()函数的主要功能是将HTTP协议标头(header)输出到浏览器.header() ...
- OpenCV imread读取图片,imshow展示图片,出现cv:Exception at memory location异常
问题如上.环境:VS2013. 代码如下: #include "stdafx.h" #include "opencv2\opencv.hpp" using na ...
- android studio 的配置
因为GFW,android studio不是下载了就可以用的,最常见的是gradle的问题,现在把自己遇到的问题记录一下,以后再配置就直接看文章就可以了 1.gradle问题,下载最新gradle,然 ...
- unity 2d 和 NGUI layer
http://blog.csdn.net/xtxy/article/details/37876825 在使用unity2d开发游戏的时候,使用了NGUI作为界面,本来二者配合得还挺好,但是一个使用场景 ...
- CCP浅谈
说明 如果想详细了解CCP,可以下载AN-AMC-1-102_Introduction_to_CCP.pdf或者ccp211.pdf 本文不涉及到专业的知识讲解,如果想查看更加专业的知识可以选择看完以 ...
- HDU 2861 四维dp打表
Patti and Terri run a bar in which there are 15 stools. One day, Darrell entered the bar and found t ...
- 20 BasicTaskScheduler0 基本任务调度类基类(二)——Live555源码阅读(一)任务调度相关类
这是Live555源码阅读的第二部分,包括了任务调度相关的三个类.任务调度是Live555源码中很重要的部分. 本文由乌合之众 lym瞎编,欢迎转载 http://www.cnblogs.com/ol ...
- linux 终端全局代理设置
http://www.webupd8.org/2010/10/how-to-set-proxy-for-terminal-quick.html 即 export http_proxy='http:// ...
- quickLinux
在cmd下稍微模仿一下linux的习惯...配置...主要是环境变量...就不用说了吧... time 要用 time.exe...可以计时...这个命令接受一个命令...可以中间有空格... ls直 ...