本文整理了Java中org.quartz.Scheduler.checkExists()
方法的一些代码示例,展示了Scheduler.checkExists()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Scheduler.checkExists()
方法的具体详情如下:
包路径:org.quartz.Scheduler
类名称:Scheduler
方法名:checkExists
[英]Determine whether a Job with the given identifier already exists within the scheduler.
[中]确定计划程序中是否已存在具有给定标识符的作业。
代码示例来源:origin: xuxueli/xxl-job
/**
* remove trigger + job
*
* @param jobName
* @param jobGroup
* @return
* @throws SchedulerException
*/
public static boolean removeJob(String jobName, String jobGroup) throws SchedulerException {
TriggerKey triggerKey = TriggerKey.triggerKey(jobName, jobGroup);
if (scheduler.checkExists(triggerKey)) {
scheduler.unscheduleJob(triggerKey); // trigger + job
}
logger.info(">>>>>>>>>>> removeJob success, triggerKey:{}", triggerKey);
return true;
}
代码示例来源: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: xuxueli/xxl-job
if (scheduler.checkExists(triggerKey)) {
return true; // PASS
代码示例来源:origin: hs-web/hsweb-framework
private void deleteJob(ScheduleJobEntity jobEntity) {
JobKey jobKey = createJobKey(jobEntity);
try {
if (scheduler.checkExists(jobKey)) {
scheduler.deleteJob(jobKey);
}
} catch (SchedulerException e) {
throw new BusinessException("更新任务失败", e, 500);
}
}
代码示例来源:origin: xuxueli/xxl-job
if (!scheduler.checkExists(triggerKey)) {
return true; // PASS
代码示例来源: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: apache/incubator-gobblin
Assert.assertFalse(scheduler._scheduler.getScheduler().checkExists(qjss1_2.getQuartzTrigger().getJobKey()));
代码示例来源:origin: bill1012/AdminEAP
public void scheduleCronJobs() throws SchedulerException {
Scheduler scheduler = schedulerFactoryBean.getScheduler();
List<ScheduleJob> jobList = getAllJobs(null, null);
for (ScheduleJob job : jobList) {
TriggerKey triggerKey = TriggerKey.triggerKey(job.getJobName(), job.getJobGroup());
// 获取trigger,即在spring配置文件中定义的bean id="myTrigger"
CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
// 不存在,创建一个
// if (null == trigger) {
if (!scheduler.checkExists(triggerKey)) {
JobDetail jobDetail = JobBuilder.newJob(QuartzJobFactory.class).withIdentity(job.getJobName(),
job.getJobGroup()).build();
// 表达式调度构建器
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression());
// 按新的cronExpression表达式构建一个新的trigger
trigger = TriggerBuilder.newTrigger().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
scheduler.scheduleJob(jobDetail, trigger);
} else {
// trigger已经存在,那么更细相应的定时设置
// 表达式调度构建器
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression());
// 按新的cronExpression表达式重新构建trigger
trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
// 按新的trigger重新设置job执行
scheduler.rescheduleJob(triggerKey, trigger);
}
}
}
代码示例来源:origin: bill1012/AdminEAP
/**
* 调度单个任务 SimpleTrigger 和 CronTrigger
*/
public void scheduleSingleJob(ScheduleJob job) throws SchedulerException, ClassNotFoundException {
Scheduler scheduler = schedulerFactoryBean.getScheduler();
// List<ScheduleJob> jobList = getAllJobs();
TriggerKey triggerKey = TriggerKey.triggerKey(job.getTriggerName(), job.getTriggerGroup());
// 获取trigger
Trigger trigger = scheduler.getTrigger(triggerKey);
// 不存在,创建一个
// if (null == trigger) {
if (!scheduler.checkExists(triggerKey)) {
JobDetail jobDetail = JobBuilder.newJob((Class<? extends Job>) Class.forName(job.getJobClass()))
.withIdentity(job.getJobName(), job.getJobGroup()).withDescription(job.getDesc()).build();
TriggerBuilder triggerBuilder = TriggerBuilder.newTrigger();
trigger = setTriggerParam(job, triggerKey, triggerBuilder, trigger);
scheduler.scheduleJob(jobDetail, trigger);
} else {
// trigger已经存在,更新相应的定时设置
TriggerBuilder triggerBuilder = trigger.getTriggerBuilder();
trigger = setTriggerParam(job, triggerKey, triggerBuilder, trigger);
// 按新的trigger重新设置job执行
scheduler.rescheduleJob(triggerKey, trigger);
}
}
代码示例来源:origin: myschedule/myschedule-quartz-extra
public boolean checkExists(JobKey jobKey) {
try {
return scheduler.checkExists(jobKey);
} catch (SchedulerException e) {
throw new QuartzRuntimeException(e);
}
}
代码示例来源:origin: myschedule/myschedule-quartz-extra
public boolean checkExists(TriggerKey triggerKey) {
try {
return scheduler.checkExists(triggerKey);
} catch (SchedulerException e) {
throw new QuartzRuntimeException(e);
}
}
代码示例来源:origin: cdapio/cdap
/**
* Asserts all the given trigger keys exist
*/
private void assertTriggerKeysExist(Collection<TriggerKey> triggerKeys)
throws SchedulerException, org.quartz.SchedulerException {
for (TriggerKey triggerKey : triggerKeys) {
if (!scheduler.checkExists(triggerKey)) {
throw new SchedulerException("Trigger with name '" + triggerKey.getName() + "' does not exist");
}
}
}
代码示例来源:origin: com.dangdang/elastic-job-cloud-executor
private void scheduleJob(final Scheduler scheduler, final JobDetail jobDetail, final String triggerIdentity, final String cron) {
try {
if (!scheduler.checkExists(jobDetail.getKey())) {
scheduler.scheduleJob(jobDetail, createTrigger(triggerIdentity, cron));
}
scheduler.start();
RUNNING_SCHEDULERS.putIfAbsent(scheduler.getSchedulerName(), scheduler);
} catch (final SchedulerException ex) {
throw new JobSystemException(ex);
}
}
代码示例来源:origin: org.jabylon/scheduler
protected void removeJob(String jobID) {
if (scheduler == null)
return;
JobKey triggerKey = new JobKey(jobID);
try {
if (scheduler.isStarted() && !scheduler.isShutdown() && scheduler.checkExists(triggerKey)) {
scheduler.deleteJob(triggerKey);
}
} catch (SchedulerException e) {
logger.error("Failed to delete job " + jobID, e);
}
}
代码示例来源:origin: com.threewks.thundr/thundr-contrib-quartz
@Override
public boolean checkExists(TriggerKey triggerKey) throws QuartzException {
try {
return delegate.checkExists(triggerKey);
} catch (SchedulerException e) {
Logger.error(e.getMessage());
throw new QuartzException(e);
}
}
代码示例来源:origin: com.threewks.thundr/thundr-contrib-quartz
@Override
public boolean checkExists(JobKey jobKey) throws QuartzException {
try {
return delegate.checkExists(jobKey);
} catch (SchedulerException e) {
Logger.error(e.getMessage());
throw new QuartzException(e);
}
}
代码示例来源:origin: com.threewks.thundr/thundr-quartz
@Override
public boolean checkExists(JobKey jobKey) throws QuartzException {
try {
return delegate.checkExists(jobKey);
} catch (SchedulerException e) {
Logger.error(e.getMessage());
throw new QuartzException(e);
}
}
代码示例来源:origin: org.seedstack.seed/seed-scheduling-support
@Override
public void unschedule(String triggerName) {
TriggerKey tk = buildTriggerKey(triggerName);
try {
if (scheduler.checkExists(tk)) {
scheduler.unscheduleJob(tk);
}
} catch (SchedulerException e) {
throw SeedException.wrap(e, SchedulerErrorCode.SCHEDULER_ERROR);
}
}
代码示例来源:origin: apache/incubator-griffin
public void deleteJob(String group, String name) throws SchedulerException {
Scheduler scheduler = factory.getScheduler();
JobKey jobKey = new JobKey(name, group);
if (!scheduler.checkExists(jobKey)) {
LOGGER.info("Job({},{}) does not exist.", jobKey.getGroup(), jobKey
.getName());
return;
}
scheduler.deleteJob(jobKey);
}
代码示例来源:origin: elasticjob/elastic-job-cloud
synchronized void register(final CloudJobConfiguration jobConfig) {
String cron = jobConfig.getTypeConfig().getCoreConfig().getCron();
JobKey jobKey = buildJobKey(cron);
repository.put(jobKey, jobConfig.getJobName());
try {
if (!scheduler.checkExists(jobKey)) {
scheduler.scheduleJob(buildJobDetail(jobKey), buildTrigger(jobKey.getName()));
}
} catch (final SchedulerException ex) {
throw new JobSystemException(ex);
}
}
内容来源于网络,如有侵权,请联系作者删除!