将多个触发器添加到单个石英作业 [英] Add multiple triggers to single quartz job

查看:130
本文介绍了将多个触发器添加到单个石英作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想动态地将触发器添加到作业,但是找不到Scheduler之外的任何有用方法

I want to dynamically add triggers to a job, but can't find any helpful methods off of Scheduler

我虽然可以调用scheduleJob方法重复进行,但是这给我tObjectAlreadyExists异常因为此标识已经存在。

I though i would just be able to call the scheduleJob method an repetitively, but this gives me tthe ObjectAlreadyExists Exception "because one already exists with this identification".

我该怎么做?

EDIT

private boolean scheduleLoadJob( XfuScheduleTimeInfo time )
{
    LoadScheduleJob job = new LoadScheduleJob( time );
    JobDetail detail;

    Integer id = Integer.valueOf( time.getScheduleId() );
    if( _hashMap.containsKey( id ) )
    {
        detail = _hashMap.get( Integer.valueOf( time.getScheduleId() ) );
    }
    else
    {
        detail = job.getDetail();
        _hashMap.put( id, detail );
    }

    try
    {
        Trigger newTrigger = job.getTrigger();
        _log.debug( "------" + newTrigger.getKey() );
        _quartzScheduler.scheduleJob( detail, newTrigger );
        return true;
    }
    catch( ParseException e )
    {
        _log.error( "Unable to parse cron expression for " + job.getInfo() );
        return false;
    }
    catch( SchedulerException e )
    {
        _log.error( "Job scheduling failed for " + job.getInfo() );
        return false;
    }
}

具有控制台输出

------ LoadJobs.Trigger-44

------ LoadJobs.Trigger-44

批量获取1个触发器

作业'LoadJobs.Job-42'的生产实例,class = com.scheduling.LoadScheduleJob

Producing instance of Job 'LoadJobs.Job-42', class=com.scheduling.LoadScheduleJob

在作业LoadJobs上调用执行。 Job-42

Calling execute on job LoadJobs.Job-42

批量获取1个触发器

工作需要:42:44

Job called for: 42 : 44

------ LoadJobs.Trigger-45

------ LoadJobs.Trigger-45

作业调度失败42:45-1/5 * *? * *

Job scheduling failed for 42 : 45 - 1/5 * * ? * *

推荐答案

这篇文章给出了提示,但是结论(schedulerInstance.add(trigger))从Quartz 2.01开始无效。

This post gives a hint, but the conclusion ( schedulerInstance.add(trigger) ) is not valid as of Quartz 2.01.

在将作业分配给触发器之后,而不是使用以下命令(一种方法是使用TriggerBuilder的forJob方法)

Instead use the following, after assinging the job to the trigger ( one way is using the TriggerBuilder's forJob method )

 schedulerInstance.scheduleJob( newTrigger )

这篇关于将多个触发器添加到单个石英作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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