前言

  系列文章:[传送门]

  项目需求:

    二维码推送到一体机上,给学生签到扫描用。然后需要的是 上课前20分钟 ,幸好在帮带我的学长做 p2p 的时候,接触过。自然 quartz 是首选。所以我就配置了下,搞了个小样例给大家。

正文 

  spring4.0 整合 Quartz 实现任务调度。这是期末项目的最后一篇,剩下到暑假吧。

    Quartz 介绍

    Quartz is a full-featured, open source job scheduling service that can be integrated with, or used along side virtually any Java application - from the smallest stand-alone application to the largest e-commerce system. Quartz can be used to create simple or complex schedules for executing tens, hundreds, or even tens-of-thousands of jobs; 

    Quartz框架是一个全功能、开源的任务调度服务,可以集成几乎任何的java应用程序—从小的单片机系统到大型的电子商务系统。Quartz可以执行上千上万的任务调度。

 

   核心概念

     Quartz核心的概念:scheduler任务调度、Job任务、Trigger触发器、JobDetail任务细节

     相关文档:http://www.quartz-scheduler.org/documentation/quartz-2.2.x/quick-start

实战 

  第一步 :spring、quartz 相应的jar包,添加到项目中(需要的call me)

    /WEB-INF/lib/quartz-2.2.1.jar

    以及spring的一些必要包

  

    第二步:web.xml中配置spring

xmlns="http://java.sun.com/xml/ns/javaee"

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

id="WebApp_ID" version="3.0">

wmuitp

org.springframework.web.context.ContextLoaderListener

contextConfigLocation

classpath:applicationContext.xml

springServlet

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:spring-mvc.xml

1

springServlet

/

encodingFilter

org.springframework.web.filter.CharacterEncodingFilter

encoding

UTF-8

forceEncoding

true

encodingFilter

/*

openSessionInViewFilter

org.springframework.orm.hibernate4.support.OpenSessionInViewFilter

openSessionInViewFilter

/*

20

java.lang.Throwable

/WEB-INF/error/500.jsp

500

/WEB-INF/error/500.jsp

404

/WEB-INF/error/404.jsp

400

/WEB-INF/error/400.jsp

   #有些你不用的,就不要写了。

 

    第三:在spring配置文件中配置quartz任务调度

    

  #目标类

    

  下面第四步:编写目标类    

package test;

import java.util.Date;

import org.quartz.JobExecutionContext;

import org.quartz.JobExecutionException;

import org.springframework.scheduling.quartz.QuartzJobBean;

public class SpringQuartzTest extends QuartzJobBean

{

/*业务实现*/

public void work() {

System.out.println("执行调度任务:"+new Date());

}

@Override

protected void executeInternal(JobExecutionContext arg0)

throws JobExecutionException {

this.work();

}

}

#需要继承QuartzJobBean测试运行结果(这个很重要 能服众)

总结

  spring quartz

  

感谢及资源共享

    

    http://url.cn/RzETYu 加入我的群

    

    路上走来一步一个脚印,希望大家和我一起。

    感谢读者!很喜欢你们给我的支持。如果支持,点个赞。

    知识来源: 《spring in action》 quartz api

查看原文