博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Quartz快速上手
阅读量:6632 次
发布时间:2019-06-25

本文共 3465 字,大约阅读时间需要 11 分钟。

快速上手你需要干啥:

        下载Quartz

        安装Quartz

        根据你的需要来配置Quartz

        开始一个示例应用

 

下载和安装

 

The Quartz JAR Files

        The main Quartz library is named quartz-xxx.jar (where xxx is a version number). In order to use any of Quartz’s features, this jar must be located on your application’s classpath.

 

        Once you’ve downloaded Quartz, unzip it somewhere, grab the quartz-xxx.jar and put it where you want it.

 

        However, if you want to make Quartz available to many applications then simply make sure it’s on the classpath of your appserver.

 

The Properties File

        Quartz uses a properties file called (kudos on the originality) quartz.properties.

        I keep all of my configuration files (including quartz.properties) in a project under the root of my application.

 

配置

 

        This is the big bit! Quartz is a very configurable application.

        The best way to configure Quartz is to edit a quartz.properties file, and place it in your application’s classpath (see Installation section above).

 

        一个基本的配置文件长这样:

 

org.quartz.scheduler.instanceName = MySchedulerorg.quartz.threadPool.threadCount = 3org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore

 

The scheduler created by this configuration has the following characteristics:

 

        org.quartz.scheduler.instanceName - This scheduler’s name will be “MyScheduler”.

 

        org.quartz.threadPool.threadCount - There are 3 threads in the thread pool, which means that a maximum of 3 jobs can be run simultaneously.

 

        org.quartz.jobStore.class - All of Quartz’s data, such as details of jobs and triggers, is held in memory (rather than in a database). Even if you have a database and want to use it with Quartz, I suggest you get Quartz working with the RamJobStore before you open up a whole new dimension by working with a database.

 

开始一个简单的应用

 

        The following code obtains an instance of the scheduler, starts it, then shuts it down:

 

QuartzTest.java

 

import org.quartz.Scheduler;import org.quartz.SchedulerException;import org.quartz.impl.StdSchedulerFactory;import static org.quartz.JobBuilder.*;import static org.quartz.TriggerBuilder.*;import static org.quartz.SimpleScheduleBuilder.*;public class QuartzTest {    public static void main(String[] args) {        try {            // Grab the Scheduler instance from the Factory            Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();            // and start it off            scheduler.start();            scheduler.shutdown();        } catch (SchedulerException se) {            se.printStackTrace();        }    }}

 

 

        Once you obtain a scheduler using StdSchedulerFactory.getDefaultScheduler(), your application will not terminate until you call scheduler.shutdown(), because there will be active threads.

 

 

        To do something interesting, you need code between the start() and shutdown() calls.

 

// define the job and tie it to our HelloJob classJobDetail job = newJob(HelloJob.class)    .withIdentity("job1", "group1")    .build();// Trigger the job to run now, and then repeat every 40 secondsTrigger trigger = newTrigger()    .withIdentity("trigger1", "group1")    .startNow()    .withSchedule(simpleSchedule()    .withIntervalInSeconds(40)    .repeatForever())                .build();// Tell quartz to schedule the job using our triggerscheduler.scheduleJob(job, trigger);

 

        (you will also need to allow some time for the job to be triggered and executed before calling shutdown() - for a simple example such as this, you might just want to add a Thread.sleep(60000) call).

 

        绑定到Hello.class上是要干啥啊?

        触发器要执行的动作是啥啊?

 

        现在你可以滚一边自己去玩了.......

转载地址:http://sbbvo.baihongyu.com/

你可能感兴趣的文章
Keras缔造者:François Chollet专访
查看>>
CSS控制ul的基础代码
查看>>
添加ESXi主机并创建虚拟机
查看>>
PowerShell在Exchange2010下快速开启邮箱[续]
查看>>
XXX管理平台系统——架构
查看>>
jasypt命令行工具的使用说明
查看>>
Skype for Business Server 2015-11-Web Application Proxy-部署
查看>>
第十八章--Ext2和Ext3文件系统
查看>>
eclipse的m2e插件的bug
查看>>
App-V序列化服务器部署,应用程序虚拟化体验系列之四
查看>>
XenApp_XenDesktop_7.6实战篇之六:DHCP服务器规划及部署
查看>>
监控Web2.0,监控你用户的满意度
查看>>
增强的Java FTP工具----扩展免费版的edtftpj
查看>>
新浪明星日志推荐系统——爬虫爬取数据(2)
查看>>
extjs radio样例集合
查看>>
小议结构体中的大小
查看>>
数据库的唯一标示符(ID)的选择
查看>>
Cocos2d-x 精灵图片预加载中不会出现重复加载问题
查看>>
让UpdatePanel支持文件上传(1):开始
查看>>
活字格企业Web应用生成器V3.0发布更新,支持插件管理和多人协作开发
查看>>