如何处理Quartz为一项工作添加一些触发器?

时间:2016-10-21 08:12:47

标签: quartz-scheduler

public static void sendEmailForNewTrigger(String jobName, String triggerName, Date sendDate) {
    try {
        Scheduler sched = QuartzSchedulerManager.getInstanceScheduler();
        JobKey jobKey = JobKey.jobKey(jobName, "group_email");
        JobDetail job = sched.getJobDetail(jobKey);
        SimpleTrigger trigger = (SimpleTrigger) newTrigger().withIdentity(triggerName)
                .startAt(sendDate)
                .build();
        if (job == null) {
            job = newJob(SendEmailJob.class).withIdentity(jobName, "group_email").build();
        }
        sched.scheduleJob(job, trigger);
        log.info(jobName + " will run at: " + sendDate);

    } catch (SchedulerException e) {
        log.error(e.toString());
        throw new RuntimeException(e.getMessage());
    }
}

在我的代码中,它不起作用,总是告诉我'无法存储作业:'group_email.send_1',因为已存在此标识。我不知道该怎么办,只想在一个工作中添加两个或更多触发器。

0 个答案:

没有答案