Lesson 1: Using Quartz
2016-04-15 11:20
274 查看
Lesson 1: Using Quartz 课程1:Quartz的使用
Before you can use the scheduler, it needs to be instantiated (who’d have guessed?). To do this, you use a SchedulerFactory. Some users of Quartz may keep an instance of a factory in a JNDI store, others may find it just as easy (or easier) to instantiate anduse a factory instance directly (such as in the example below).
可以使用调度程序之前,它需要被初始化(谁能想不到呢?)。初始化,你使用SchedulerFactory。
Once a scheduler is instantiated, it can be started, placed in stand-by mode, and shutdown. Note that once a scheduler is shutdown, it cannot be restarted without being re-instantiated. Triggers do not fire (jobs do not execute) until the scheduler has been
started, nor while it is in the paused state.
Here’s a quick snippet of code, that instantiates and starts a scheduler, and schedules a job for execution:
SchedulerFactory schedFact = new org.quartz.impl.StdSchedulerFactory(); Scheduler sched = schedFact.getScheduler(); sched.start(); // define the job and tie it to our HelloJob class JobDetail job = newJob(HelloJob.class) .withIdentity("myJob", "group1") .build(); // Trigger the job to run now, and then every 40 seconds Trigger trigger = newTrigger() .withIdentity("myTrigger", "group1") .startNow() .withSchedule(simpleSchedule() .withIntervalInSeconds(40) .repeatForever()) .build(); // Tell quartz to schedule the job using our trigger sched.scheduleJob(job, trigger);
As you can see, working with quartz is rather simple. In Lesson
2 we’ll give a quick overview of Jobs and Triggers, and Quartz’s API so that you can more fully understand this example.
相关文章推荐
- view的focusable属性改变设置是否可获取光标
- LightOJ 1247 Matrix Game (尼姆博弈)
- js 引号问题
- Ubuntu14.04安装配置Hadoop2.6.0(完全分布式)与 wordcount实例运行
- Linux基础知识汇总
- 欢迎使用CSDN-markdown编辑器
- 快速幂取模,POJ(1995)
- LeetCode(61)-Valid Palindrome
- linux内核部件分析之——设备驱动模型之class
- IOS 通用静态库、Makefile文件使用
- LeetCode(61)-Valid Palindrome
- LeetCode(61)-Valid Palindrome
- json解析和构建
- TCP/IP常见问题总结(三)
- HTML5移动网站制作教程
- pyqt4的qwebpage一个奇怪的bug
- java DateUtil
- ListView 各行变色写法
- LeetCode OJ 61. Rotate List
- 详解设计模式(四)