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,以便让你可以更充分地理解这个示例。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 本文是根据 Quartz定时器官方文档翻译的,只翻译了第1到第10课,如有翻译不精确的地方,请读者指正,互相学习,...
    ChinaXieShuai阅读 8,482评论 1 19
  • application [ˌæplɪ'keɪʃ(ə)n]应用程式应用、应用程序 application frame...
    我不白先生阅读 2,099评论 0 3
  • 1.Quartz大致介绍 1.1介绍 Quartz是OpenSymphony开源组织在Job scheduling...
    smallmartial阅读 375评论 0 6
  • 一.介绍 Quartz 是一个完全由 Java 编写的开源作业调度框架,为在 Java 应用程序中进行作业调度提供...
    Jaypc阅读 716评论 0 0
  • 今天感恩节哎,感谢一直在我身边的亲朋好友。感恩相遇!感恩不离不弃。 中午开了第一次的党会,身份的转变要...
    迷月闪星情阅读 10,610评论 0 11