Quartz教程 第1课:使用Quartz

选择课程:

第1课:使用Quartz

第2课:Quartz API,以及作业和触发器简介

第3课:有关工作和JobDetails的更多信息

第4课:有关触发器的更多信息

第5课:SimpleTriggers

第6课:CronTriggers

第7课:TriggerListeners和JobListeners

第8课:SchedulerListeners

第9课:JobStores

第10课:配置,资源使用和SchedulerFactory

第11课:高级(企业)功能

第12课:其他功能

选择一个特殊主题:

CronTrigger教程


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

一旦一个调度器被实例化,它就可以被启动、处于stand-by  模式以及关机。请注意,一旦调度程序关闭,就不能在不重新实例化的情况下重新启动它。触发器在启动调度器之前不会触发(作业不会执行),也不会在调度器处于暂停状态时触发。

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

猜你喜欢

转载自blog.csdn.net/qq_30336433/article/details/80927815