快速上手你需要干啥:

下载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 = MyScheduler
org.quartz.threadPool.threadCount = 3
org.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 class
JobDetail job = newJob(HelloJob.class)
.withIdentity("job1", "group1")
.build(); // Trigger the job to run now, and then repeat every 40 seconds
Trigger trigger = newTrigger()
.withIdentity("trigger1", "group1")
.startNow()
.withSchedule(simpleSchedule()
.withIntervalInSeconds(40)
.repeatForever())
.build(); // Tell quartz to schedule the job using our trigger
scheduler.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上是要干啥啊?

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

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

Quartz快速上手的更多相关文章

  1. Quartz.NET快速上手第一课(官网文档翻译)

    Quartz.NET快速上手第一课(官网文档翻译) 原文链接 在你使用调度者(scheduler)之前,你需要对它进行实例化(谁能猜到这呢?).在实例化scheduler时候,你需要使用ISchedu ...

  2. Quartz高可用定时任务快速上手

    定时任务使用指南 如果你想做定时任务,有高可用方面的需求,或者仅仅想入门快,上手简单,那么选用它准没错. 定时任务模块是对Quartz框架进一步封装,使用更加简洁. 1.引入依赖 <depend ...

  3. 想要快速上手 Spring Boot?看这些教程就足够了!| 码云周刊第 81 期

    原文:https://blog.gitee.com/2018/08/19/weekly-81/ 想要快速上手 Spring Boot?看这些教程就足够了!| 码云周刊第 81 期 码云周刊 | 201 ...

  4. 【Python五篇慢慢弹】快速上手学python

    快速上手学python 作者:白宁超 2016年10月4日19:59:39 摘要:python语言俨然不算新技术,七八年前甚至更早已有很多人研习,只是没有现在流行罢了.之所以当下如此盛行,我想肯定是多 ...

  5. 快速上手Unity原生Json库

    现在新版的Unity(印象中是从5.3开始)已经提供了原生的Json库,以前一直使用LitJson,研究了一下Unity用的JsonUtility工具类的使用,发现使用还挺方便的,所以打算把项目中的J ...

  6. [译]:Xamarin.Android开发入门——Hello,Android Multiscreen快速上手

    原文链接:Hello, Android Multiscreen Quickstart. 译文链接:Hello,Android Multiscreen快速上手 本部分介绍利用Xamarin.Androi ...

  7. [译]:Xamarin.Android开发入门——Hello,Android快速上手

    返回索引目录 原文链接:Hello, Android_Quickstart. 译文链接:Xamarin.Android开发入门--Hello,Android快速上手 本部分介绍利用Xamarin开发A ...

  8. 快速上手seajs——简单易用Seajs

    快速上手seajs——简单易用Seajs   原文  http://www.cnblogs.com/xjchenhao/p/4021775.html 主题 SeaJS 简易手册 http://yslo ...

  9. Git版本控制Windows版快速上手

    说到版本控制,之前用过VSS,SVN,Git接触不久,感觉用着还行.写篇博文给大家分享一下使用Git的小经验,让大家对Git快速上手. 说白了Git就是一个控制版本的工具,其实没想象中的那么复杂,咱在 ...

随机推荐

  1. js apply与call的用法与区别

    apply和call function Person(c, d) { return this.a + this.b + c + d } var  o = {a: 1, b: 2} Person.cal ...

  2. lnmp1.4 nginx配置thinkphp5

    vhost/xxx.conf配置图,重点是红色框框 研究了两三天 ,至此thinkphp5 路由,隐藏index.php全部解决 感谢网友的分享:http://blog.csdn.net/gaoxiu ...

  3. owncloud 安装

    假定lamp已安装完成. 1 安装owncloud 使用curl命令下载其发行版密钥(key),并使用add命令将其与apt-key实用程序一起导入: curl https://download.ow ...

  4. GPT-2,吓坏创造者的「深度造假写手」

    简评: 今年二月份刷屏的 GPT-2 着实厉害,那个生成续写故事的例子更是效果好到吓人一跳,它到底有多厉害,本文略微讲讲.更详细的信息可参考文末 OpenAI 的博客链接. 你能从下面这两段文字里品味 ...

  5. sudo 及visudo用法

    visudo 编辑sudoers文件 1.命令功能 bisudo命令是专门用来编辑/etc/sudoers文件,同时提供语法检查等功能./etc/sudoes文件是sudo命令的配置文件. 2.语法格 ...

  6. PHP漏洞函数

    1. is_numeric函数 bool is_numeric ( mixed $var ) 此函数用于判断变量是否数字或者数字字符串,不仅能接受十进制,还能接受十六进制,这样就有了绕过的方法 < ...

  7. [BZOJ1299]巧克力棒(博弈论,线性基)

    [BZOJ1299]巧克力棒 Description TBL和X用巧克力棒玩游戏.每次一人可以从盒子里取出若干条巧克力棒,或是将一根取出的巧克力棒吃掉正整数长度.TBL先手两人轮流,无法操作的人输. ...

  8. VS2013 删除"附加依赖项"中“继承的值”

    经过好几次尝试,都无法在VS2013中直接删除“继承的值”,于是另辟蹊径,找到了一种解决方法. 相对而言,在 VS2010 中干这件事会容易一点,或者说,成功率更高一点,于是,我的思路就是再装一个 V ...

  9. C++11 学习笔记

    unique_ptr 可以实现如下功能: 1.为动态申请的内存提供异常安全 2.讲动态申请的内存所有权传递给某函数 3.从某个函数返回动态申请内存的所有权 4.在容器中保存指针 5.auto_ptr ...

  10. netty学习第5章 netty整合websocket

    学习netty之后,可能都有一个疑问,就是如何选择一个编码.解码器,在netty中的编解码可是和json这种编解码是不一样的,netty的编解码器主要是解决TCP粘包.拆包的问题.netty中有许多自 ...