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

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值