Quartz手册 - Lesson 1: Using Quartz

Table of Contents | Lesson 2 ›

Lesson 1: Using 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 and use a factory instance directly (such as in the example below).

scheduler实例化之后才能被使用。你可以使用ScheduleFactory来实例化。你可以在JDNI store中维护一个Quartz的实例,也可以使用一种更为简便的方式,也就是直接使用工厂来创建实例(例子如下):

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.

当Scheduler实例化以后,就可以启动(就绪状态)和关闭它。注意,当scheduler被关闭以后,除非重新实例化,否则不能直接重启。triggers在scheduler启动之前不会工作,及时trigger处于暂停状态(任务也不会执行)。

Here’s a quick snippet of code, that instantiates and starts a scheduler, and schedules a job for execution:

下面是实例化scheduler、启动scheduler和编排任务的代码片段: 

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.

就和你看到的一样,运行quartz非常简单。在Lesson 2中我们会快速浏览Jobs、Triggers和Quartz的API来帮助更好的理解这个例子。

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值