Schedule Job with custom Trigger and params
I am using the Grails Quartz plugin and want to schedule my jobs with a programmatically-created Trigger. I do not know beforehand what the execution interval will be. I want the job to execute indefinitely.
The docs give some examples of how to schedule/trigger jobs:
== Dynamic Jobs Scheduling ==
Starting from 0.4.1 version you have the ability to schedule job executions dynamically.
These methods are available:
MyJob.schedule(String cronExpression, Map params?)
creates cron trigger; MyJob.schedule(Long repeatInterval, Integer repeatCount?, Map params?)
creates simple trigger: repeats job repeatCount+1 times with delay of repeatInterval milliseconds; MyJob.schedule(Date scheduleDate, Map params?)
schedules one job execution to the specific date; MyJob.schedule(Trigger trigger)
schedules job's execution with a custom trigger; MyJob.triggerNow(Map params?)
force immediate execution of the job.
Each method (except the one for custom trigger) takes optional 'params' argument. You can use it to pass some data to your job and then access it from the job.
Grails Version 1.3.7 Quartz Plugin version 0.4.2
So, why does the MyJob.schedule(Trigger trigger)
not take params? And, how can I achieve what I want, using a custom trigger and a map or params for the Job?
If you look where these methods are defined in the Quartz plugin sourcecode, you can see that all of the functions that take Map params
are wrappers which create a Trigger
and then fire it off to the scheduler.
The MyJob.schedule(Trigger trigger)
method, just fires off the trigger you pass it, so it is up to you to add your params into the Triggers jobDataMap
property before you call this method, ie:
trigger.jobDataMap.putAll [foo:"It Works!"]
MyJob.schedule( trigger )
tim答案是正确的,这里有点更新。
Trigger trigger = TriggerBuilder
.newTrigger()
.startNow()
.withIdentity("triggerName", "groupName")
.withSchedule(
SimpleScheduleBuilder.simpleSchedule()
.withIntervalInSeconds(5000).repeatForever()
).build();
trigger.jobDataMap.putAll([foo:"bar"])
MyJob.schedule(trigger)
链接地址: http://www.djcxy.com/p/23624.html
上一篇: 多个Quartz调度器来运行相同的工作
下一篇: 使用自定义触发器和参数计划作业