1,Pom.xml   加入:quartz-2.1.7.jar

<dependency>

<groupId>org.quartz-scheduler</groupId>

<artifactId>quartz</artifactId>

<version>2.1.7</version>

</dependency>

2,定义任务类

package com.xinwei.util;

import com.xinwei.rbac.service.CommonBizService;

import com.xinwei.util.spring.SpringFactory;

public class UpdateCurrentValueTask {

static CommonBizService service;

static {

service = (CommonBizService) SpringFactory

.getBean("commonBizServiceImpl");

}

public void doTask(){

System.out.println("do quertz scheduler... ...");

service.updateCurrentValueBySeqName("group_id_seq");

}

}

3, spring-scheduler.xml

<?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:jdbc="http://www.springframework.org/schema/jdbc"

xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"

xmlns:aop="http://www.springframework.org/schema/aop"

xmlns:jpa="http://www.springframework.org/schema/data/jpa"

xsi:schemaLocation="

      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd

      http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd

      http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd

      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd

      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd

      http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"

default-lazy-init="false">

<!-- 任务管理器 -->

<beans>

<!-- 要调用的工作类 -->

<bean id="quartzJob" class="com.xinwei.util.UpdateCurrentValueTask"></bean>

<!-- 定义调用对象和调用对象的方法 多个任务定义多个-->

<bean id="jobtask2"

class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">

<!-- 调用的类 -->

<property name="targetObject">

<ref bean="quartzJob" />

</property>

<!-- 调用类中的方法 -->

<property name="targetMethod">

<value>doTask</value>

</property>

</bean>

<!-- 定义触发时间 -->

<bean id="doTime2"

class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">

<property name="jobDetail">

<ref bean="jobtask2" />

</property>

<!-- cron表达式  每天24:00运行一次 -->

<property name="cronExpression" value="0 0 0 * * ?" />

</bean>

<!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序 -->

<bean id="startQuertz" lazy-init="false" autowire="no"

class="org.springframework.scheduling.quartz.SchedulerFactoryBean">

<property name="triggers">

<list>

<ref bean="doTime2"/>

</list>

</property>

</bean>

</beans>

</beans>

4,web.xml中管理上述schduler

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

version="2.5">

<display-name>security</display-name>

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>

classpath*:/applicationContext.xml,

classpath*:/applicationContext-shiro.xml,

classpath*:/spring-scheduler.xml

</param-value>

</context-param>

<listener>

<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

<!-- 主要注册request,在普通类中获取request对象 -->

<listener>

<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>

</listener>

<filter>

<filter-name>encodingFilter</filter-name>

<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>

<init-param>

<param-name>encoding</param-name>

<param-value>UTF-8</param-value>

</init-param>

<init-param>

<param-name>forceEncoding</param-name>

<param-value>true</param-value>

</init-param>

</filter>

<filter-mapping>

<filter-name>encodingFilter</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

<!-- 过滤参数,将前台传输的参数request. page.去掉 -->

<filter>

<filter-name>ParameterFilter</filter-name>

<filter-class>com.xinwei.filter.ParameterFilter</filter-class>

<init-param>

<param-name>blackListURL</param-name> <!-- 配置黑名单url 表示不走过滤器的url order:1 -->

<param-value>

/js/**

/css/**

/styles/**

/images/**

/plugins/**

/fonts/**

/login/timeout

/logout

/views/**

</param-value>

</init-param>

<init-param>

<param-name>whiteListURL</param-name> <!-- 配置白名单url 表示走过滤器的url order:2-->

<param-value>

/**

</param-value>

</init-param>

</filter>

<filter-mapping>

<filter-name>ParameterFilter</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

<!-- pagination filter -->

<filter>

<filter-name>PageFilter</filter-name>

<filter-class>com.xinwei.filter.PageFilter</filter-class>

<init-param>

<param-name>blackListURL</param-name> <!-- 配置黑名单url 表示不走过滤器的url order:1 -->

<param-value></param-value>

</init-param>

<init-param>

<param-name>whiteListURL</param-name> <!-- 配置白名单url 表示走过滤器的url order:2-->

<param-value>

/**/list

</param-value>

</init-param>

</filter>

<filter-mapping>

<filter-name>PageFilter</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

<!-- <filter> <filter-name>openEntityManagerInViewFilter</filter-name> <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>

</filter> <filter-mapping> <filter-name>openEntityManagerInViewFilter</filter-name>

<url-pattern>/*</url-pattern> </filter-mapping> -->

<filter>

<filter-name>shiroFilter</filter-name>

<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>

<init-param>

<param-name>targetFilterLifecycle</param-name>

<param-value>true</param-value>

</init-param>

</filter>

<filter-mapping>

<filter-name>shiroFilter</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

<servlet>

<servlet-name>springServlet</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<init-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath*:/spring-mvc.xml</param-value>

</init-param>

<init-param>

<param-name>dispatchOptionsRequest</param-name>

<param-value>true</param-value>

</init-param>

<load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>springServlet</servlet-name>

<url-pattern>/</url-pattern>

</servlet-mapping>

<servlet>

<servlet-name>hessianServlet</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<init-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:/server/hessian-server.xml</param-value>

</init-param>

<load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>hessianServlet</servlet-name>

<url-pattern>/hessian/*</url-pattern>

</servlet-mapping>

<session-config>

<session-timeout>30</session-timeout>

</session-config>

<error-page>

<exception-type>java.lang.Throwable</exception-type>

<location>/WEB-INF/views/error/500.jsp</location>

</error-page>

<error-page>

<error-code>500</error-code>

<location>/WEB-INF/views/error/500.jsp</location>

</error-page>

<error-page>

<error-code>404</error-code>

<location>/WEB-INF/views/error/404.jsp</location>

</error-page>

<error-page>

<error-code>403</error-code>

<location>/WEB-INF/views/error/403.jsp</location>

</error-page>

</web-app>

quartz demo01的更多相关文章

  1. 免费开源的DotNet任务调度组件Quartz.NET(.NET组件介绍之五)

    很多的软件项目中都会使用到定时任务.定时轮询数据库同步,定时邮件通知等功能..NET Framework具有“内置”定时器功能,通过System.Timers.Timer类.在使用Timer类需要面对 ...

  2. Quartz

    Quartz是一个开源的作业调度框架,它完全由Java写成,并设计用于J2SE和J2EE应用中.它提供了巨大的灵 活性而不牺牲简单性.你能够用它来为执行一个作业而创建简单的或复杂的调度. eg: ja ...

  3. Spring Quartz实现任务调度

    任务调度 在企业级应用中,经常会制定一些"计划任务",即在某个时间点做某件事情 核心是以时间为关注点,即在一个特定的时间点,系统执行指定的一个操作 任务调度涉及多线程并发.线程池维 ...

  4. topshelf和quartz内部分享

    阅读目录: 介绍 基础用法 调试及安装 可选配置 多实例支持及相关资料 quartz.net 上月在公司内部的一次分享,现把PPT及部分交流内容整理成博客. 介绍 topshelf是创建windows ...

  5. Quartz.net持久化与集群部署开发详解

    序言 我前边有几篇文章有介绍过quartz的基本使用语法与类库.但是他的执行计划都是被写在本地的xml文件中.无法做集群部署,我让它看起来脆弱不堪,那是我的罪过. 但是quart.net是经过许多大项 ...

  6. Quartz.net开源作业调度框架使用详解

    前言 quartz.net作业调度框架是伟大组织OpenSymphony开发的quartz scheduler项目的.net延伸移植版本.支持 cron-like表达式,集群,数据库.功能性能强大更不 ...

  7. quartz.net 时间表达式----- Cron表达式详解

    序言 Cron表达式:就是用简单的xxoo符号按照一定的规则,就能把各种时间维度表达的淋漓尽致,无所不在其中,然后在用来做任务调度(定时服务)的quart.net中所认知执行,可想而知这是多么的天衣无 ...

  8. Quartz.NET Windows 服务示例

    想必大家在项目中处理简单的后台持续任务或者定时触发任务的时候均使用 Thread 或者 Task 来完成,但是项目中的这种需求一旦多了的话就得将任务调度引入进来了,那今天就简单的介绍一下 Quartz ...

  9. [Quartz笔记]玩转定时调度

    简介 Quartz是什么? Quartz是一个特性丰富的.开源的作业调度框架.它可以集成到任何Java应用. 使用它,你可以非常轻松的实现定时任务的调度执行. Quartz的应用场景 场景1:提醒和告 ...

随机推荐

  1. composer命令详解

    composer命令行 你已经学会了如何使用命令行界面做一些事情.本章将向你介绍所有可用的命令. 为了从命令行获得帮助信息,请运行composer或者composer list 命令,然后结合--he ...

  2. 转:Java中子类是否可以继承父类的static变量和方法而呈现多态特性

    原文地址:Java中子类是否可以继承父类的static变量和方法而呈现多态特性 静态方法 通常,在一个类中定义一个方法为static,那就是说,无需本类的对象即可调用此方法,关于static方法,声明 ...

  3. /var/run/utmp文件操作函数

    相关函数:getutent, getutid, getutline, setutent, endutent, pututline, utmpname utmp 结构定义如下:struct utmp{  ...

  4. scapy 中的ARP

    scapy 常用命令 ls() //查看支持的协议对象lsc() //查看函数show() //查看数据包结构send() //三层发包sr() //三层收发sr1() //三层收发只收一 timeo ...

  5. 使用Redis 计数器防止刷接口

    业务需求中经常有需要用到计数器的场景:为了防止恶意刷接口,需要设置一个接口每个IP一分钟.一天等的调用次数阈值:为了降低费用,限制发送短信的次数等.使用Redis的Incr自增命令可以轻松实现以上需求 ...

  6. MySQL中varchar最大长度是多少?

    一. varchar存储规则: 4.0版本以下,varchar(20),指的是20字节,如果存放UTF8汉字时,只能存6个(每个汉字3字节) 5.0版本以上,varchar(20),指的是20字符,无 ...

  7. Laravel编辑产品-CRUD之edit和update

    上一篇讲了Laravel展示产品-CRUD之show,现在我们说一下Laravel编辑产品,涉及到编辑和更新, 1,定义controller,update和create有点相似,我们复制一份过来修改. ...

  8. 自定义UIProgressView

    自定义CustomporgressView #import <UIKit/UIKit.h> @interface CustomporgressView : UIView @property ...

  9. what's the 套期保值

    出自 MBA智库百科(https://wiki.mbalib.com/) 什么是套期保值 套期保值是指把期货市场当作转移价格风险的场所,利用期货合约作为将来在现货市场上买卖商品的临时替代物,对其现在买 ...

  10. Linux系统上传文件与下载文件命令

    我们用的服务器都是Linux系统的,如果用的是远程服务器,就需要将我们的代码推送过去,这里可以用到PSCP命令. (一)上传 pscp 本机文件的路径以及文件名 远程主机的用户名@远程主机IP:想要存 ...