java - 如何使用具有相同 CronTrigger 对象的 Quartz 调度两次调度作业?
问题描述
我正在使用 Quartz-Scheduler 来安排任务。我的要求是在给定日期范围之间有两个触发器,一个在开始时间,一个在结束时间。
IE -String startDateStr = "2013-09-27 00:00:00.0";
String endDateStr = "2013-09-31 00:00:00.0";
expecting first trigger at 09:00 AM
expecting second trigger at 12:00 PM
我如何使用动态 cron 表达式来实现相同的目的。对此的任何帮助将不胜感激。期待中的感谢
public class CronJob {
public static void main(String[] args) throws ParseException, SchedulerException {
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
JobDetail job = newJob(TestJob.class)
.withIdentity("cronJob", "testJob")
.build();
String startDateStr = "2013-09-27 00:00:00.0";
String endDateStr = "2013-09-31 00:00:00.0";
Date startDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S").parse(startDateStr);
Date endDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S").parse(endDateStr);
CronTrigger cronTrigger = newTrigger()
.withIdentity("trigger1", "testJob")
.startAt(startDate)
.withSchedule(CronScheduleBuilder.cronSchedule("0 0 9-12 * * ?").withMisfireHandlingInstructionDoNothing())
.endAt(endDate)
.build();
scheduler.scheduleJob(job, cronTrigger);
scheduler.start();
}
public static class TestJob implements Job {
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
System.out.println("this is a cron scheduled test job");
}
}
}
解决方案
推荐阅读
- python - XML到base64使用python
- swift - UITableView.appearance().backgroundColor init 基于horizontalSiceClass
- php - 页面模板上的 wordpress get_header() 获取正文标记内的头部内容
- c# - 如何以流的形式读取 xml 属性值的内容
- sql - 添加标记列的最大值和最小值的列
- qt - 在qt中重新启动应用程序后如何使计数器连续
- php - 带有 laravel 的 Plesk PHP 电子邮件未收到 DKIM 签名
- javascript - 表单:在表单提交之前使用 jQuery 验证特殊情况
- algorithm - 无交叉连接桥梁——动态规划算法设计
- java - IntelliJ LibGDX 错误“org.lwjgl.LWJGLException:像素格式未加速”