第一步:下载所需的Jar包 
commons-beanutils.ja、commons-collections.jar、commons-logging.jar、commons-digester.jar、quartz.jar包 
第二步:在web.xml下配置监听 
在web.xml下配置监听的目的是为了项目编译的时候就自动运行监听下配置的业务类。

<!--监听(作用就是启动项目的时候就会运行这个类,这个类需要实现ServletContextListener接口)-->
<listener>
<listener-class>
com.qt.quartz.QuartzMain
</listener-class>
</listener>

第三步:编写com.qt.quartz.QuartzMain类 
这个类只是作为启动类,调用QuartzLoad类的2个方法,因为这个类是静态的,所以可以用名称直接点出方法名称。

package com.qt.quartz;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
public class QuartzMain implements ServletContextListener {
// 服务器启动时执行该事件
@Override
public void contextInitialized(ServletContextEvent arg0) {
try {
QuartzLoad.run();
} catch (Exception e) {
e.printStackTrace();
}
}
// 服务器停止时执行该事件
@Override
public void contextDestroyed(ServletContextEvent arg0) {
try {
QuartzLoad.stop();
} catch (Exception e) {
e.printStackTrace();
}
} }

第四步:编写com.qt.quartz.QuartzLoad类 
这个类里面有2个方法,一个是启动quartz的方法,一个是关闭方法,这个类里面可以定制每隔多少时间循环调用业务类一次。

package com.qt.quartz;
import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.impl.StdSchedulerFactory; public class QuartzLoad {
private static Scheduler sched;
public static void run() throws Exception {
//创建LzstoneTimeTask的定时任务
//三个参数,第一个是自己取得名称、第二个是固定的、第三个是业务类
JobDetail jobDetail = new JobDetail("lzstoneJob",sched.DEFAULT_GROUP,QuartzJob.class);
//三个参数,第一个是自己取得名称、第二个是触发器组名称、第三个是自定义时间
CronTrigger trigger = new CronTrigger("lzstoneTrigger","lzstone","0/50 * * * * ?");
sched = new StdSchedulerFactory().getScheduler();
sched.scheduleJob(jobDetail,trigger);
sched.start();
}
//停止
public static void stop() throws Exception{
sched.shutdown();
}
}

序号 说明 是否必填 允许填写的值 允许的通配符 
1 秒 是 0-59 , - * / 
2 分 是 0-59 , - * / 
3 小时 是 0-23 , - * / 
4 日 是 1-31 , - * ? / L W 
5 月 是 1-12 or JAN-DEC , - * / 
6 周 是 1-7 or SUN-SAT , - * ? / L # 
7 年 否 empty 或 1970-2099 , - * /

第五步:编写QuartzJob.class类,自己的业务处理类

package com.qt.quartz;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException; public class QuartzJob implements Job{
@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
// TODO Auto-generated method stub
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");
System.out.println("时间表:"+sdf.format(new Date()));
}
}

quartz在web.xml的配置的更多相关文章

  1. JavaWeb工程中web.xml基本配置

    一.理论准备 先说下我记得xml规则,必须有且只有一个根节点,大小写敏感,标签不嵌套,必须配对. web.xml是不是必须的呢?不是的,只要你不用到里面的配置信息就好了,不过在大型web工程下使用该文 ...

  2. spring web.xml 难点配置总结

    web.xml web.xml是所有web项目的根源,没有它,任何web项目都启动不了,所以有必要了解相关的配置. ContextLoderListener,ContextLoaderServlet, ...

  3. web.xml 文件配置01

    web.xml 文件配置01   前言:一般的web工程中都会用到web.xml,方便开发web工程.web.xml主要用来配置Filter.Listener.Servlet等.但是要说明的是web. ...

  4. SSH web.xml文件配置

    启动一个WEB项目的时候, WEB容器会去读取它的配置文件web.xml web.xml中配置的加载优先级:context-param -> listener -> filter -> ...

  5. 在web.xml中配置error-page

    在web.xml中配置error-page 在web.xml中有两种配置error-page的方法,一是通过错误码来配置,而是通过异常的类型来配置,分别举例如下: 一.   通过错误码来配置error ...

  6. Struts2 web.xml文件配置

    在导入了项目需要使用的核心jar包之后需要在web.xml中配置Struts. 1. Struts2的知识点普及: Struts2共有5类配置文件,分别罗列如下: 1), Web.xml; 在没有使用 ...

  7. struts2在web.xml中配置详情

    web.xml是web应用中载入有关servlet信息的重要配置文件,起着初始化servlet,filter等web程序的作用. 通常,全部的MVC框架都须要Web应用载入一个核心控制器.那採取什么方 ...

  8. web.xml中配置log4j

    1.将 commons-logging.jar和 log4j.jar加入你的项目中:2.在src/下创建log4j.properties|log4j.xml文件:3.在web.xml中配置log4j的 ...

  9. web.xml中配置Spring中applicationContext.xml的方式

    2011-11-08 16:29 web.xml中配置Spring中applicationContext.xml的方式 使用web.xml方式加载Spring时,获取Spring applicatio ...

随机推荐

  1. DRF 的视图,路由和渲染器

    DRF 的视图,路由和渲染器 1 视图 简单的增删改查 : ModelViewSet; 复杂的操作使用APIView 和 GenericViewSet APIView(View) class Home ...

  2. 基于Python和Tornado的WEB Terminal

    https://github.com/liftoff/GateOne 亮点有以下: ↪ Clientless ↪ Multi-User and Multi-Session ↪ Multi-Auth a ...

  3. GoogLeNet 神经网络结构

    GoogLeNet是2014年 ILSVRC 冠军模型,top-5 错误率 6.7% ,GoogLeNet做了更大胆的网络上的尝试而不像vgg继承了lenet以及alexnet的一些框架,该模型虽然有 ...

  4. Java连接Mysql的基本用法

    Java连接数据库(以MySQL为例)2007-04-05 02:23           这篇文章主要以MySQL为例讲下Java如何连接到数据库的. 当然,首先要安装有JDK(一般是JDK1.5. ...

  5. django初探-创建简单的博客系统(一)

    django第一步 1. django安装 pip install django print(django.get_version()) 查看django版本 2. 创建项目 打开cmd,进入指定目录 ...

  6. 【转载】Allegro Auto Rename器件反标注教程

    Cadence设计时一般不主张在PCB文件中更改Logic(PADS的ECO更改),不过Auto Rename仍然是非常实用的功能,按照布局重排位号,可以让PCB的丝印标识更清晰,容易检查,位号易找, ...

  7. goreplay(gor) golang 流量拷贝工具试用

    1. 项目地址 https://github.com/buger/goreplay 2. 安装 wget https://github.com/buger/goreplay/releases/down ...

  8. 使用.NET Remoting开发分布式应用——基于租约的生存期

    一.概述 知名类型的SingleCall对象可以在客户程序的方法调用之后被垃圾收集器清理掉,因为它没有保持状态,属于无状态的.而客户激活的类型的对象和知名类型的SingleTon对象都属于生存期长的对 ...

  9. Mysql 拿指定经纬度与数据库多条经纬度进行距离计算 (转)

    公式如下,单位米: 第一点经纬度:lng1 lat1 第二点经纬度:lng2 lat2 round(6378.138*2*asin(sqrt(pow(sin( (lat1*pi()/180-lat2* ...

  10. nginx虚拟主机的配置

    nginx虚拟主机的配置 server { listen ; server_name 127.0.0.1; access_log off; root /var/www/html/; location ...