org.quartz.Scheduler.scheduleJob()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(190)

本文整理了Java中org.quartz.Scheduler.scheduleJob()方法的一些代码示例,展示了Scheduler.scheduleJob()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Scheduler.scheduleJob()方法的具体详情如下:
包路径:org.quartz.Scheduler
类名称:Scheduler
方法名:scheduleJob

Scheduler.scheduleJob介绍

[英]Schedule the given job with the related set of triggers.

If any of the given job or triggers already exist (or more specifically, if the keys are not unique) and the replace parameter is not set to true then an exception will be thrown.
[中]使用相关的触发器集安排给定的作业。
如果任何给定的作业或触发器已经存在(或者更具体地说,如果键不是唯一的),并且replace参数未设置为true,则将引发异常。

代码示例

代码示例来源:origin: kairosdb/kairosdb

@Override
public void schedule(JobDetail jobDetail, Trigger trigger) throws KairosDBException
{
  checkNotNull(jobDetail);
  checkNotNull(trigger);
  try
  {
    scheduler.scheduleJob(jobDetail, trigger);
  }
  catch (SchedulerException e)
  {
    throw new KairosDBException("Failed to schedule trigger " + jobDetail, e);
  }
}

代码示例来源:origin: jooby-project/jooby

@PostConstruct
public void start() throws Exception {
 for (Entry<JobDetail, Trigger> job : jobs) {
  JobDetail detail = job.getKey();
  Trigger trigger = job.getValue();
  log.info("  {} {}", detail.getKey(), describe(trigger));
  scheduler.scheduleJob(detail, trigger);
 }
 scheduler.start();
}

代码示例来源:origin: stackoverflow.com

Trigger trigger = TriggerBuilder.newTrigger().withIdentity("simple").withSchedule(
      CronScheduleBuilder.cronSchedule("0 0/1 * 1/1 * ? *")).startNow().build();
  scheduler.scheduleJob(jobDetail, trigger);
  scheduler.start();
} catch (Exception e) {

代码示例来源:origin: xuxueli/xxl-job

Date date = scheduler.scheduleJob(jobDetail, cronTrigger);

代码示例来源:origin: apache/shiro

scheduler.scheduleJob(detail, trigger);
if (schedulerImplicitlyCreated) {
  scheduler.start();

代码示例来源:origin: Netflix/Priam

/** Add a task to the scheduler */
public void addTask(String name, Class<? extends Task> taskclass, TaskTimer timer)
    throws SchedulerException, ParseException {
  assert timer != null : "Cannot add scheduler task " + name + " as no timer is set";
  JobDetail job =
      JobBuilder.newJob()
          .withIdentity(name, Scheduler.DEFAULT_GROUP)
          .ofType(taskclass)
          .build(); // new JobDetail(name, Scheduler.DEFAULT_GROUP, taskclass);
  if (timer.getCronExpression() != null && !timer.getCronExpression().isEmpty()) {
    logger.info(
        "Scheduled task metadata.  Task name: {}" + ", cron expression: {}",
        taskclass.getName(),
        timer.getCronExpression());
  } else {
    logger.info("Scheduled task metadata.  Task name: {}", taskclass.getName());
  }
  scheduler.scheduleJob(job, timer.getTrigger());
}

代码示例来源:origin: elasticjob/elastic-job-lite

/**
 * 调度作业.
 * 
 * @param cron CRON表达式
 */
public void scheduleJob(final String cron) {
  try {
    if (!scheduler.checkExists(jobDetail.getKey())) {
      scheduler.scheduleJob(jobDetail, createTrigger(cron));
    }
    scheduler.start();
  } catch (final SchedulerException ex) {
    throw new JobSystemException(ex);
  }
}

代码示例来源:origin: Netflix/Priam

try {
  sleeper.sleepQuietly(delayInSeconds * 1000L);
  scheduler.scheduleJob(job, timer.getTrigger());
} catch (SchedulerException e) {
  logger.warn(

代码示例来源:origin: gocd/gocd

private void scheduleNewBackupJob(BackupConfig newBackupConfig) {
  if (newBackupConfig == null || isBlank(newBackupConfig.getSchedule())) {
    return;
  }
  try {
    JobDetail jobDetail = newJob()
        .withIdentity(jobKey())
        .ofType(ScheduleBackupQuartzJob.class)
        .usingJobData(jobDataMap())
        .build();
    CronTrigger trigger = newTrigger()
        .withIdentity(triggerKey())
        .withSchedule(cronSchedule(new CronExpression(newBackupConfig.getSchedule())))
        .build();
    quartzScheduler.scheduleJob(jobDetail, trigger);
    LOG.info("Initialized backup job with schedule " + newBackupConfig.getSchedule());
    clearServerHealthError();
  } catch (SchedulerException e) {
    LOG.error("Unable to schedule backup job", e);
    setServerHealthError("Unable to schedule backup job.", "Check the server log for detailed errors: " + e.getMessage());
  } catch (ParseException e) {
    LOG.error("Unable to schedule backup job", e);
    setServerHealthError("Unable to schedule backup job.", "Invalid cron syntax for backup configuration at offset " + e.getErrorOffset() + ": " + e.getMessage());
  }
}

代码示例来源:origin: wuyouzhuguli/FEBS-Shiro

/**
 * 创建定时任务
 */
public static void createScheduleJob(Scheduler scheduler, Job scheduleJob) {
  try {
    // 构建job信息
    JobDetail jobDetail = JobBuilder.newJob(ScheduleJob.class).withIdentity(getJobKey(scheduleJob.getJobId()))
        .build();
    // 表达式调度构建器
    CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCronExpression())
        .withMisfireHandlingInstructionDoNothing();
    // 按新的cronExpression表达式构建一个新的trigger
    CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(scheduleJob.getJobId()))
        .withSchedule(scheduleBuilder).build();
    // 放入参数,运行时的方法可以获取
    jobDetail.getJobDataMap().put(Job.JOB_PARAM_KEY, scheduleJob);
    scheduler.scheduleJob(jobDetail, trigger);
    // 暂停任务
    if (scheduleJob.getStatus().equals(Job.ScheduleStatus.PAUSE.getValue())) {
      pauseJob(scheduler, scheduleJob.getJobId());
    }
  } catch (SchedulerException e) {
    log.error("创建定时任务失败", e);
  }
}

代码示例来源:origin: spring-projects/spring-framework

if (jobDetail != null && this.jobDetails != null && !this.jobDetails.contains(jobDetail) &&
    (this.overwriteExistingJobs || getScheduler().getJobDetail(jobDetail.getKey()) == null)) {
  getScheduler().scheduleJob(jobDetail, trigger);
  this.jobDetails.add(jobDetail);
  getScheduler().scheduleJob(trigger);

代码示例来源:origin: apache/incubator-gobblin

/** {@inheritDoc} */
@Override protected JobSpecSchedule doScheduleJob(JobSpec jobSpec, Runnable jobRunnable) {
 // Build a data map that gets passed to the job
 JobDataMap jobDataMap = new JobDataMap();
 jobDataMap.put(JOB_SPEC_KEY, jobSpec);
 jobDataMap.put(JOB_RUNNABLE_KEY, jobRunnable);
 // Build a Quartz job
 JobDetail job = JobBuilder.newJob(QuartzJob.class)
   .withIdentity(jobSpec.getUri().toString())
   .withDescription(Strings.nullToEmpty(jobSpec.getDescription()))
   .usingJobData(jobDataMap)
   .build();
 Trigger jobTrigger = createTrigger(job.getKey(), jobSpec);
 QuartzJobSchedule jobSchedule = new QuartzJobSchedule(jobSpec, jobRunnable, jobTrigger);
 try {
  _scheduler.getScheduler().scheduleJob(job, jobTrigger);
  getLog().info(String.format("Scheduled job %s next two fire times: %s , %s.", jobSpec, jobTrigger.getNextFireTime(),
    jobTrigger.getFireTimeAfter(jobTrigger.getNextFireTime())));
 } catch (SchedulerException e) {
  throw new RuntimeException("Scheduling failed for " + jobSpec + ":" + e, e);
 }
 return jobSchedule;
}

代码示例来源:origin: gocd/gocd

private void scheduleJob(Scheduler scheduler, PipelineConfig pipelineConfig) {
  TimerConfig timer = pipelineConfig.getTimer();
  if (timer != null) {
    try {
      CronTrigger trigger = newTrigger()
          .withIdentity(triggerKey(CaseInsensitiveString.str(pipelineConfig.name()), PIPELINE_TRIGGGER_TIMER_GROUP))
          .withSchedule(cronSchedule(new CronExpression(timer.getTimerSpec())))
          .build();
      JobDetail jobDetail = newJob()
          .withIdentity(jobKey(CaseInsensitiveString.str(pipelineConfig.name()), PIPELINE_TRIGGGER_TIMER_GROUP))
          .ofType(SchedulePipelineQuartzJob.class)
          .usingJobData(jobDataMapFor(pipelineConfig))
          .build();
      scheduler.scheduleJob(jobDetail, trigger);
      LOG.info("Initialized timer for pipeline {} with {}", pipelineConfig.name(), timer.getTimerSpec());
    } catch (ParseException e) {
      showPipelineError(pipelineConfig, e,
          "Bad timer specification for timer in Pipeline: " + pipelineConfig.name(),
          "Cannot schedule pipeline using the timer");
    } catch (SchedulerException e) {
      showPipelineError(pipelineConfig, e,
          "Could not register pipeline '" + pipelineConfig.name() + "' with timer",
          "");
    }
  }
}

代码示例来源:origin: Dreampie/Resty

.withSchedule(cronSchedule(this.cron)).build();
this.scheduleTime = sched.scheduleJob(job, trigger);
sched.start();
Quartzer.addQuartzJob(this);

代码示例来源:origin: quartz-scheduler/quartz

.build();
getScheduler().scheduleJob(job, trig);
getLog().debug("Scheduled file scan job for data file: {}, at interval: {}", jobFile.getFileName(), scanInterval);

代码示例来源:origin: quartz-scheduler/quartz

.build();
getScheduler().scheduleJob(job, trig);
getLog().debug("Scheduled file scan job for data file: {}, at interval: {}", jobFile.getFileName(), scanInterval);

代码示例来源:origin: hs-web/hsweb-framework

protected void startJob(ScheduleJobEntity jobEntity) {
  try {
    if (scheduler.checkExists(createJobKey(jobEntity))) {
      return;
    }
    JobDetail jobDetail = JobBuilder
        .newJob(DynamicJob.class)
        .withIdentity(createJobKey(jobEntity))
        .setJobData(createJobDataMap(jobEntity.getParameters()))
        .usingJobData(DynamicJobFactory.JOB_ID_KEY, jobEntity.getId())
        .withDescription(jobEntity.getName() + (jobEntity.getRemark() == null ? "" : jobEntity.getRemark()))
        .build();
    MutableTrigger trigger = scheduleTriggerBuilder.buildTrigger(jobEntity.getQuartzConfig());
    trigger.setKey(createTriggerKey(jobEntity));
    scheduler.scheduleJob(jobDetail, trigger);
  } catch (SchedulerException e) {
    throw new BusinessException("启动定时调度失败", e);
  }
}

代码示例来源:origin: AxonFramework/AxonFramework

@Override
public ScheduleToken schedule(Instant triggerDateTime, Object event) {
  Assert.state(initialized, () -> "Scheduler is not yet initialized");
  EventMessage eventMessage = GenericEventMessage.asEventMessage(event);
  String jobIdentifier = JOB_NAME_PREFIX + eventMessage.getIdentifier();
  QuartzScheduleToken tr = new QuartzScheduleToken(jobIdentifier, groupIdentifier);
  try {
    JobDetail jobDetail = buildJobDetail(eventMessage, new JobKey(jobIdentifier, groupIdentifier));
    scheduler.scheduleJob(jobDetail, buildTrigger(triggerDateTime, jobDetail.getKey()));
  } catch (SchedulerException e) {
    throw new SchedulingException("An error occurred while setting a timer for a saga", e);
  }
  return tr;
}

代码示例来源:origin: AxonFramework/AxonFramework

@Override
public String schedule(Instant triggerDateTime,
            String deadlineName,
            Object messageOrPayload,
            ScopeDescriptor deadlineScope) {
  DeadlineMessage<Object> deadlineMessage = asDeadlineMessage(deadlineName, messageOrPayload);
  String deadlineId = JOB_NAME_PREFIX + deadlineMessage.getIdentifier();
  runOnPrepareCommitOrNow(() -> {
    DeadlineMessage interceptedDeadlineMessage = processDispatchInterceptors(deadlineMessage);
    try {
      JobDetail jobDetail = buildJobDetail(interceptedDeadlineMessage,
                         deadlineScope,
                         new JobKey(deadlineId, deadlineName));
      scheduler.scheduleJob(jobDetail, buildTrigger(triggerDateTime, jobDetail.getKey()));
    } catch (SchedulerException e) {
      throw new DeadlineException("An error occurred while setting a timer for a deadline", e);
    }
  });
  return deadlineId;
}

代码示例来源:origin: changmingxie/tcc-transaction

public void init() {
  try {
    MethodInvokingJobDetailFactoryBean jobDetail = new MethodInvokingJobDetailFactoryBean();
    jobDetail.setTargetObject(transactionRecovery);
    jobDetail.setTargetMethod("startRecover");
    jobDetail.setName("transactionRecoveryJob");
    jobDetail.setConcurrent(false);
    jobDetail.afterPropertiesSet();
    CronTriggerFactoryBean cronTrigger = new CronTriggerFactoryBean();
    cronTrigger.setBeanName("transactionRecoveryCronTrigger");
    cronTrigger.setCronExpression(transactionConfigurator.getRecoverConfig().getCronExpression());
    cronTrigger.setJobDetail(jobDetail.getObject());
    cronTrigger.afterPropertiesSet();
    scheduler.scheduleJob(jobDetail.getObject(), cronTrigger.getObject());
    scheduler.start();
  } catch (Exception e) {
    throw new SystemException(e);
  }
}

相关文章