Quartz 2.3.0 文檔中英文參考 Lesson 1: Using Quartz

修改及建議:https://github.com/clxering/Quartz-Doc-Chinese-English-bilingual/blob/dev/Tutorials/Lesson-1

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).

在使用調度程序之前,你需要使用 SchedulerFactory 對它進行實例化(誰能猜到呢?)。一些 Quartz 用戶可能在 JNDI 存儲中保存工廠實例,其他用戶可能會發現直接實例化與使用工廠實例同樣容易(或更容易),如下面的示例。

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.

如你所見,使用 quartz 相當簡單。在第二課中,我們將快速概述作業和觸發器,以及 Quartz 的 API,以便讓你可以更充分地理解這個示例。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章