调度 Quartz 作业

Scheduling a Quartz job

我想开发一个 quartz 作业,它将 运行 在作业中指定的特定时间。但是当我开始工作时,它会在那个时间开始,而不是在代码中指定的那个时间。

请帮忙。

这是我的代码:

import java.util.TimeZone;

import org.quartz.CronScheduleBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;

public class CronScheluderForActivityMilestone {

public boolean CronScheluderForActivityMilestone() throws Exception {

    SchedulerFactory sf = new StdSchedulerFactory();
    Scheduler sche = sf.getScheduler();
    sche.start();
    JobDetail jDetail = new JobDetail("SendMailOnActivityMileStone", "SendMailOnActivityMileStone", ActivityMileStoneSendMail.class);

    Trigger trigger = TriggerBuilder.newTrigger()
            .withIdentity("mytriggerForActivityMileStone", "SendMailOnActivityMileStone")
            .withSchedule(CronScheduleBuilder.dailyAtHourAndMinute(19, 00).inTimeZone(TimeZone.getTimeZone("Asia/Calcutta")))
            .forJob("SendMailOnActivityMileStone", "SendMailOnActivityMileStone")
            .build();

   sche.scheduleJob(jDetail, trigger);      
    return true;    
   }
  }

您应该像这样更改您的 inTimeZone 配置:

Trigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger3", "group1")
.withSchedule(weeklyOnDayAndHourAndMinute(DateBuilder.WEDNESDAY, 10, 42)
.inTimeZone(TimeZone.getTimeZone("America/Los_Angeles")))
.forJob(job)
.build();

inTimeZone属于withSchedule()