public void addPeriodJob(JobInfo jinfo, PeriodInfo pinfo, JobDataMap jdatamap) throws Exception
{
int repeat = pinfo.getRepeatCount();
Date start = pinfo.getStartTime();
JobInfo jobinfo = getJobInfo(jinfo);
if (start == null)
start = new Date();
if (repeat <= 0)
repeat = SimpleTrigger.REPEAT_INDEFINITELY;
else
repeat = repeat - 1;
Trigger trigger =
TriggerBuilder
.newTrigger()
.withIdentity(jobinfo.getJobName(), jobinfo.getGroupName())
.withSchedule(
SimpleScheduleBuilder.simpleSchedule().withRepeatCount(repeat)
.withIntervalInMilliseconds(pinfo.getRepeatInterval())).startAt(start).endAt(pinfo.getEndTime())
.build();
@SuppressWarnings("unchecked")
JobBuilder jb =
JobBuilder.newJob(jobinfo.getJob()).withIdentity(jobinfo.getJobName(), jobinfo.getGroupName())
.withDescription(jinfo.getDescription());
JobDetail job = jdatamap == null ? jb.build() : jb.usingJobData(jdatamap).build();
scheduleJob(job, trigger);
}