Quartz调度程序 - 之间的时间 [英] Quartz scheduler-Time between

查看:287
本文介绍了Quartz调度程序 - 之间的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用石英调度程序来安排工作。我有一个案例,我希望每天晚上(晚上9点)到第二天早上(06:00 AM)执行工作。我怎样才能实现这一点。目前我正在初始化这样的触发器

I am using quartz scheduler for scheduling jobs.I have a case where i want to execute a job every day night(9:00 PM) to next day morning(06:00 AM).How can i achieve this.Currently i am initializing trigger like this

      Trigger trigger2 = newTrigger()
    .withIdentity("trigger1", "group1")
    .startNow()
    .withSchedule(simpleSchedule()
            .withIntervalInSeconds(10)
            .repeatForever())            
    .build();

我需要做些什么修改来满足要求?

What modification i need to make to satisfy the requirement?

推荐答案

如果您需要每天运行一份工作,您只需要指定工作的开始时间:

If your need is to run a job ONCE every day you need to only specify the start time of the job:

newTrigger().withSchedule(
      CronScheduleBuilder.dailyAtHourAndMinute(21,0)).build();

如果预定作业(数据库处理)花费很多时间,Quartz调度程序无法帮助您超过6AM的时间限制。 Quartz只会启动这项工作。你应该在早上6点停止正在运行的工作。例如,假设作业是一种方法:

Quartz scheduler can't help you if the scheduled job (database processing) takes many hours and it might get over the 6AM time limit. Quartz only starts the job. You should stop yourself the running job at 6AM. For example suppose the job is a method:

public void doSomeDBOperations() {
    while(have more data to process) {
        if(Calendar.getInstance().get(Calendar.HOUR_OF_DAY) == 6) {
           break;
        }

        //insert data
    }
}

这篇关于Quartz调度程序 - 之间的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆