本文整理匯總了Java中org.quartz.JobBuilder類的典型用法代碼示例。如果您正苦於以下問題:Java JobBuilder類的具體用法?Java JobBuilder怎麽用?Java JobBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JobBuilder類屬於org.quartz包,在下文中一共展示了JobBuilder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: refreshMetadata
import org.quartz.JobBuilder; //導入依賴的package包/類
/**
* Refresh metadata. Schedules the job to retrieve metadata.
* @throws SchedulerException the scheduler exception
*/
@PostConstruct
public void refreshMetadata() throws SchedulerException {
final Thread thread = new Thread(new Runnable() {
@Override
public void run() {
buildMetadataResolverAggregate();
}
});
thread.start();
final JobDetail job = JobBuilder.newJob(this.getClass())
.withIdentity(this.getClass().getSimpleName()).build();
final Trigger trigger = TriggerBuilder.newTrigger()
.withSchedule(SimpleScheduleBuilder.simpleSchedule()
.withIntervalInMinutes(this.refreshIntervalInMinutes)
.repeatForever()).build();
final SchedulerFactory schFactory = new StdSchedulerFactory();
final Scheduler sch = schFactory.getScheduler();
sch.start();
sch.scheduleJob(job, trigger);
}
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:27,代碼來源:StaticMetadataResolverAdapter.java
示例2: scheduleJob
import org.quartz.JobBuilder; //導入依賴的package包/類
/**
* The user may configure this binding to update the internal clock of
* FHT80b devices via rf command. The method takes care of scheduling this
* job.
*/
private JobKey scheduleJob(Class<? extends Job> jobClass, String cronExpression) {
JobKey jobKey = null;
try {
Scheduler sched = StdSchedulerFactory.getDefaultScheduler();
JobDetail detail = JobBuilder.newJob(jobClass).withIdentity("FHT "+jobClass.getSimpleName(), "cul").build();
detail.getJobDataMap().put(FHTBinding.class.getName(), this);
CronTrigger trigger = TriggerBuilder.newTrigger().forJob(detail)
.withSchedule(CronScheduleBuilder.cronSchedule(cronExpression)).build();
jobKey = detail.getKey();
sched.scheduleJob(detail, trigger);
} catch (SchedulerException e) {
logger.error("Can't schedule time update job", e);
}
return jobKey;
}
示例3: schedule
import org.quartz.JobBuilder; //導入依賴的package包/類
protected <T extends Job> void schedule(final Class<T> reference, final Map<String, Object> jobMap)
throws JobExecutionException {
@SuppressWarnings("unchecked")
T jobInstance = (T) ApplicationContextProvider.getBeanFactory().
createBean(reference, AbstractBeanDefinition.AUTOWIRE_BY_TYPE, false);
String jobName = getClass().getName() + UUID.randomUUID();
jobMap.put(JobManager.DOMAIN_KEY, AuthContextUtils.getDomain());
ApplicationContextProvider.getBeanFactory().registerSingleton(jobName, jobInstance);
JobBuilder jobDetailBuilder = JobBuilder.newJob(reference).
withIdentity(jobName).
usingJobData(new JobDataMap(jobMap));
TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger().
withIdentity(JobNamer.getTriggerName(jobName)).
startNow();
try {
scheduler.getScheduler().scheduleJob(jobDetailBuilder.build(), triggerBuilder.build());
} catch (SchedulerException e) {
throw new JobExecutionException("Could not schedule, aborting", e);
}
}
示例4: addSchedule
import org.quartz.JobBuilder; //導入依賴的package包/類
/**
* 增加一個調度任務(cron版)
*
* @param name
* 任務名稱
* @param job
* 執行內容
* @param cronExpression
* cron表達式
* @throws SchedulerException
*/
public Trigger addSchedule(String name, Class<? extends Job> task, String cronExpression, JobDataMap param)
throws SchedulerException {
Scheduler sched = SF.getScheduler();
JobBuilder builder = JobBuilder.newJob(task);
builder.withIdentity(name, Scheduler.DEFAULT_GROUP);
if (param != null) {
builder.usingJobData(param);
}
Trigger trigger = TriggerBuilder.newTrigger().withIdentity(name, Scheduler.DEFAULT_GROUP)
.withSchedule(CronScheduleBuilder.cronSchedule(cronExpression)).build();
sched.scheduleJob(builder.build(), trigger);
if (!sched.isShutdown())
sched.start();
return trigger;
}
示例5: create
import org.quartz.JobBuilder; //導入依賴的package包/類
@Override
public void create(ScheduleJob scheduleJob) throws SchedulerException {
Scheduler scheduler = schedulerFactoryBean.getScheduler();
Class<? extends Job> jobClass = null;
try {
jobClass = (Class<? extends Job>) Class.forName(scheduleJob.getJobClassName());
} catch (ClassNotFoundException e) {
throw new SchedulerException(e);
}
if (null != jobClass) {
JobDetail jobDetail = JobBuilder.newJob(jobClass)
.withIdentity(scheduleJob.getJobName(), scheduleJob.getJobGroupName())
.withDescription(scheduleJob.getJobDescription()).build();
Trigger trigger = TriggerBuilder.newTrigger()
.withIdentity(scheduleJob.getTriggerName(), scheduleJob.getTriggerGroupName())
.withDescription(scheduleJob.getTriggerDescription())
.withSchedule(CronScheduleBuilder.cronSchedule(scheduleJob.getTriggerCronExpression())).startNow()
.build();
scheduler.scheduleJob(jobDetail, trigger);
}
}
示例6: addMethodInovkeJob
import org.quartz.JobBuilder; //導入依賴的package包/類
public JobDetail addMethodInovkeJob(String schedulerName, String jobName, String jobGroup, String jobClass,
Object[] constructorArguments, String jobClassMethodName,
Object[] jobClassMethodArgs, String description) throws SchedulerException {
Assert.notNull(jobClass, "jobClass can not be null");
Assert.notEmpty(schedulerName, "schedulerName can not be empty");
Assert.notEmpty(jobName, "jobName can not be empty");
Assert.notEmpty(jobGroup, "jobGroup can not be empty");
Assert.notEmpty(jobClassMethodName, "jobClassMethodName can not be empty");
JobDataMap jobDataMap = new JobDataMap();
jobDataMap.put("jobClass", jobClass);
jobDataMap.put("constructorArguments", constructorArguments);
jobDataMap.put("jobClassMethodName", jobClassMethodName);
jobDataMap.put("jobClassMethodArgs", jobClassMethodArgs);
JobDetail jobDetail = JobBuilder.newJob(MethodInvokeJob.class).withIdentity(jobName, jobGroup)
.withDescription(description).setJobData(jobDataMap).storeDurably().build();
addJob(schedulerName, jobDetail);
return jobDetail;
}
示例7: updateMethodInovkeJob
import org.quartz.JobBuilder; //導入依賴的package包/類
public JobDetail updateMethodInovkeJob(String schedulerName, String jobName, String jobGroup, String jobClass,
Object[] constructorArguments, String jobClassMethodName,
Object[] jobClassMethodArgs, String description) throws SchedulerException {
Assert.notNull(jobClass, "jobClass can not be null");
Assert.notEmpty(schedulerName, "schedulerName can not be empty");
Assert.notEmpty(jobName, "jobName can not be empty");
Assert.notEmpty(jobGroup, "jobGroup can not be empty");
Assert.notEmpty(jobClassMethodName, "jobClassMethodName can not be empty");
JobDataMap jobDataMap = new JobDataMap();
jobDataMap.put("jobClass", jobClass);
jobDataMap.put("constructorArguments", constructorArguments);
jobDataMap.put("jobClassMethodName", jobClassMethodName);
jobDataMap.put("jobClassMethodArgs", jobClassMethodArgs);
JobDetail jobDetail = JobBuilder.newJob(MethodInvokeJob.class).withIdentity(jobName, jobGroup)
.withDescription(description).setJobData(jobDataMap).storeDurably().build();
updateJob(schedulerName, jobDetail);
return jobDetail;
}
示例8: addStatefulMethodJob
import org.quartz.JobBuilder; //導入依賴的package包/類
public JobDetail addStatefulMethodJob(String schedulerName, String jobName, String jobGroup, String jobClass,
Object[] constructorArguments, String jobClassMethodName,
Object[] jobClassMethodArgs, String description) throws SchedulerException {
Assert.notNull(jobClass, "jobClass can not be null");
Assert.notEmpty(schedulerName, "schedulerName can not be empty");
Assert.notEmpty(jobName, "jobName can not be empty");
Assert.notEmpty(jobGroup, "jobGroup can not be empty");
Assert.notEmpty(jobClassMethodName, "jobClassMethodName can not be empty");
JobDataMap jobDataMap = new JobDataMap();
jobDataMap.put("jobClass", jobClass);
jobDataMap.put("constructorArguments", constructorArguments);
jobDataMap.put("jobClassMethodName", jobClassMethodName);
jobDataMap.put("jobClassMethodArgs", jobClassMethodArgs);
JobDetail jobDetail = JobBuilder.newJob(StatefulMethodInvokeJob.class).withIdentity(jobName, jobGroup)
.withDescription(description).setJobData(jobDataMap).storeDurably().build();
addJob(schedulerName, jobDetail);
return jobDetail;
}
示例9: updateStatefulMethodJob
import org.quartz.JobBuilder; //導入依賴的package包/類
public JobDetail updateStatefulMethodJob(String schedulerName, String jobName, String jobGroup, String jobClass,
Object[] constructorArguments, String jobClassMethodName,
Object[] jobClassMethodArgs, String description) throws SchedulerException {
Assert.notNull(jobClass, "jobClass can not be null");
Assert.notEmpty(schedulerName, "schedulerName can not be empty");
Assert.notEmpty(jobName, "jobName can not be empty");
Assert.notEmpty(jobGroup, "jobGroup can not be empty");
Assert.notEmpty(jobClassMethodName, "jobClassMethodName can not be empty");
JobDataMap jobDataMap = new JobDataMap();
jobDataMap.put("jobClass", jobClass);
jobDataMap.put("constructorArguments", constructorArguments);
jobDataMap.put("jobClassMethodName", jobClassMethodName);
jobDataMap.put("jobClassMethodArgs", jobClassMethodArgs);
JobDetail jobDetail = JobBuilder.newJob(StatefulMethodInvokeJob.class).withIdentity(jobName, jobGroup)
.withDescription(description).setJobData(jobDataMap).storeDurably().build();
updateJob(schedulerName, jobDetail);
return jobDetail;
}
示例10: startAndSchedule
import org.quartz.JobBuilder; //導入依賴的package包/類
public synchronized void startAndSchedule(Integer jobIntervalSeconds) throws SchedulerException {
if (!scheduler.isStarted()) {
logger.debug(DEBUG_JOBS_INIT_STARTING_MESSAGE);
scheduler.start();
JobDetail job = JobBuilder.newJob(FetchEventsJob.class).build();
Trigger trigger = TriggerBuilder.newTrigger().startNow().withSchedule(
SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(jobIntervalSeconds).repeatForever())
.build();
scheduler.scheduleJob(job, trigger);
logger.debug(DEBUG_JOBS_INIT_DONE_MESSAGE);
} else {
logger.debug(DEBUG_SCHEDULER_IS_ALREADY_STARTED_MESSAGE);
}
}
示例11: afterPropertiesSet
import org.quartz.JobBuilder; //導入依賴的package包/類
@Override
public void afterPropertiesSet () throws Exception
{
Map<String, AbstractJob> webappBeanNames =
applicationContext.getBeansOfType (AbstractJob.class);
triggers = new HashMap<> ();
for (String webappBeanName : webappBeanNames.keySet ())
{
AbstractJob cron = webappBeanNames.get (webappBeanName);
CronTriggerFactoryBean trigger = new CronTriggerFactoryBean ();
JobDetail job = JobBuilder.newJob (cron.getClass ()).
storeDurably (true).build ();
trigger.setJobDetail (job);
trigger.setCronExpression (cron.getCronExpression ());
trigger.setName (webappBeanName + "Trigger");
trigger.afterPropertiesSet ();
triggers.put (cron.getClass(), trigger.getObject ());
}
super.setTriggers (triggers.values ().toArray (
new Trigger[triggers.size ()]));
super.setJobFactory (autowiringJobFactory);
super.afterPropertiesSet ();
}
示例12: updateJob
import org.quartz.JobBuilder; //導入依賴的package包/類
public void updateJob(String group, String name, JobDescriptor descriptor) {
try {
JobDetail oldJobDetail = scheduler.getJobDetail(jobKey(name, group));
if(Objects.nonNull(oldJobDetail)) {
JobDataMap jobDataMap = oldJobDetail.getJobDataMap();
jobDataMap.put("subject", descriptor.getSubject());
jobDataMap.put("messageBody", descriptor.getMessageBody());
jobDataMap.put("to", descriptor.getTo());
jobDataMap.put("cc", descriptor.getCc());
jobDataMap.put("bcc", descriptor.getBcc());
JobBuilder jb = oldJobDetail.getJobBuilder();
JobDetail newJobDetail = jb.usingJobData(jobDataMap).storeDurably().build();
scheduler.addJob(newJobDetail, true);
log.info("Updated job with key - {}", newJobDetail.getKey());
return;
}
log.warn("Could not find job with key - {}.{} to update", group, name);
} catch (SchedulerException e) {
log.error("Could not find job with key - {}.{} to update due to error - {}", group, name, e.getLocalizedMessage());
}
}
示例13: enableSessionValidation
import org.quartz.JobBuilder; //導入依賴的package包/類
public void enableSessionValidation() {
if (log.isDebugEnabled()) {
log.debug("Scheduling session validation job using Quartz with session validation interval of ["
+ this.sessionValidationInterval + "]ms...");
}
try {
SimpleTrigger trigger = TriggerBuilder.newTrigger().startNow().withIdentity(JOB_NAME, Scheduler.DEFAULT_GROUP)
.withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInMilliseconds(sessionValidationInterval))
.build();
JobDetail detail = JobBuilder.newJob(QuartzSessionValidationJob.class)
.withIdentity(JOB_NAME, Scheduler.DEFAULT_GROUP).build();
detail.getJobDataMap().put(SESSION_MANAGER_KEY, this.sessionManager);
Scheduler scheduler = getScheduler();
scheduler.scheduleJob(detail, trigger);
if (this.schedulerImplicitlyCreated) {
scheduler.start();
if (log.isDebugEnabled()) {
log.debug("Successfully started implicitly created Quartz Scheduler instance.");
}
}
this.enabled = true;
if (log.isDebugEnabled())
log.debug("Session validation job successfully scheduled with Quartz.");
} catch (SchedulerException e) {
if (log.isErrorEnabled())
log.error("Error starting the Quartz session validation job. Session validation may not occur.", e);
}
}
示例14: run
import org.quartz.JobBuilder; //導入依賴的package包/類
@Override
public void run(String... strings) throws Exception {
try {
/*
* 在 Quartz 中, scheduler 由 SchedulerFactory創建:DirectSchedulerFactory 或者
* StdSchedulerFactory。第二種工廠 StdSchedulerFactory 使用較多,因為
* DirectSchedulerFactory 使用起來不夠方便,需要作許多詳細的手工編碼設置。
*/
// 獲取Scheduler實例
scheduler = StdSchedulerFactory.getDefaultScheduler();
scheduler.start();
// System.out.println("scheduler.start");
// System.out.println(scheduler.getSchedulerName());
// 注冊任務
JobDetail jobDetail = JobBuilder.newJob(QuartzTask.class).withIdentity("QuartzTaskJob", "QuartzTaskGroup").build();
// 設置出發時間(每1天執行1次)
SimpleScheduleBuilder simpleScheduleBuilder = SimpleScheduleBuilder.simpleSchedule().withIntervalInHours(24).repeatForever();
Trigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger", "group").startNow().withSchedule(simpleScheduleBuilder).build();
// 交由Scheduler安排觸發
scheduler.scheduleJob(jobDetail, trigger);
} catch (SchedulerException e) {
e.printStackTrace();
}
}
示例15: serverTasks
import org.quartz.JobBuilder; //導入依賴的package包/類
public serverTasks() throws SchedulerException, ParseException{
/*
* 循環式的
*/
SchedulerFactory factory = new StdSchedulerFactory();
Scheduler scheduler = factory.getScheduler();
//設置啟動時間
DateBuilder.evenMinuteDate(new Date());
JobDetail job = JobBuilder.newJob(job.class).withIdentity("job1", "group1").build();
//job.getJobDataMap().put("a", true);//實現傳參
// @NOTICE
// 與SimpleTrigger對比:類不同了,現在的是Trigger的子類CronTrigger;withSchedule中的參數變為CronScheduleBuilder了
// CronScheduleBuilder可以通過類似"0/13 * * * * ?"這種表達式來創建定時任務
// 當前這個表達式的定義是30分鍾執行一次
CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger1", "group1")
.withSchedule(CronScheduleBuilder.cronSchedule("1 0/30 * * * ?")).build();
scheduler.scheduleJob(job, trigger);
scheduler.start();
//scheduler.shutdown(true);
}