當前位置: 首頁>>代碼示例>>Java>>正文


Java CronScheduleBuilder類代碼示例

本文整理匯總了Java中org.quartz.CronScheduleBuilder的典型用法代碼示例。如果您正苦於以下問題:Java CronScheduleBuilder類的具體用法?Java CronScheduleBuilder怎麽用?Java CronScheduleBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CronScheduleBuilder類屬於org.quartz包,在下文中一共展示了CronScheduleBuilder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: buildTrigger

import org.quartz.CronScheduleBuilder; //導入依賴的package包/類
@SuppressWarnings({ "unchecked", "rawtypes" })
private Trigger buildTrigger(String confId, JobScheduling conf, JobKey job) {

    TriggerKey key = this.buildTiggerKey(confId);
    TriggerBuilder trigger = TriggerBuilder.newTrigger().withIdentity(key);

    // Set CRON value
    if (StringUtils.isNotEmpty(conf.getValue())) {
        trigger.withSchedule(CronScheduleBuilder.cronSchedule(conf.getValue()));
    }

    // Set DATE value
    if (conf.getStartAt() > 0) {
        trigger.startAt(new Date(conf.getStartAt()));
    }

    if (job != null) {
        trigger.forJob(job);
    }

    return trigger.build();
}
 
開發者ID:AirVantage,項目名稱:av-sched,代碼行數:23,代碼來源:JobSchedulingServiceImpl.java

示例2: scheduleJob

import org.quartz.CronScheduleBuilder; //導入依賴的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;
}
 
開發者ID:andrey-desman,項目名稱:openhab-hdl,代碼行數:22,代碼來源:FHTBinding.java

示例3: addSchedule

import org.quartz.CronScheduleBuilder; //導入依賴的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;
}
 
開發者ID:HankXV,項目名稱:Limitart,代碼行數:27,代碼來源:SchedulerUtil.java

示例4: modifyJobTime

import org.quartz.CronScheduleBuilder; //導入依賴的package包/類
/** 
 * @Description: 修改一個任務的觸發時間(使用默認的任務組名,觸發器名,觸發器組名)  
 * @param jobName 
 * @param time 
 *  
 */  
@SuppressWarnings("unchecked")    
public static void modifyJobTime(String jobName, String time) {   
    TriggerKey triggerKey = TriggerKey.triggerKey(  
            jobName, TRIGGER_GROUP_NAME);  
      
    try {    
        Scheduler sched = gSchedulerFactory.getScheduler();    
        CronTrigger trigger =(CronTrigger) sched.getTrigger(triggerKey);  
        if (trigger == null) {    
            return;    
        }    
        String oldTime = trigger.getCronExpression();    
        if (!oldTime.equalsIgnoreCase(time)) {  
            CronScheduleBuilder scheduleBuilder =CronScheduleBuilder.cronSchedule(time);  
            //按新的cronExpression表達式重新構建trigger  
            trigger = trigger.getTriggerBuilder().withIdentity(triggerKey)  
            .withSchedule(scheduleBuilder).build();  
            //按新的trigger重新設置job執行  
            sched.rescheduleJob(triggerKey, trigger);  
        }    
    } catch (Exception e) {    
        throw new RuntimeException(e);    
    }    
}
 
開發者ID:jeffreyning,項目名稱:nh-micro,代碼行數:31,代碼來源:MicroQuartzManager.java

示例5: create

import org.quartz.CronScheduleBuilder; //導入依賴的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);
	}
}
 
開發者ID:easynet-cn,項目名稱:easynetcn-cloud,代碼行數:26,代碼來源:JobServiceImpl.java

示例6: persistTrigger

import org.quartz.CronScheduleBuilder; //導入依賴的package包/類
/**
 * Persist the trigger in the Quartz scheduler.
 */
private VmSchedule persistTrigger(final VmSchedule schedule) throws SchedulerException {
	// The trigger for the common VM Job will the following convention :
	// schedule.id-subscription.id
	final String id = VmJob.format(schedule);
	final JobDetailImpl object = (JobDetailImpl) vmJobDetailFactoryBean.getObject();
	object.getJobDataMap().put("vmServicePlugin", this);
	final Trigger trigger = TriggerBuilder.newTrigger().withIdentity(id, SCHEDULE_TRIGGER_GROUP)
			.withSchedule(CronScheduleBuilder.cronSchedule(schedule.getCron()).inTimeZone(DateUtils.getApplicationTimeZone()))
			.forJob(object).usingJobData("subscription", schedule.getSubscription().getId())
			.usingJobData("operation", schedule.getOperation().name()).usingJobData("schedule", schedule.getId()).build();

	// Add this trigger
	vmSchedulerFactoryBean.getObject().scheduleJob(trigger);
	return schedule;
}
 
開發者ID:ligoj,項目名稱:plugin-vm,代碼行數:19,代碼來源:VmResource.java

示例7: getScheduleBuilder

import org.quartz.CronScheduleBuilder; //導入依賴的package包/類
/**
 * Get a {@link ScheduleBuilder} that is configured to produce a 
 * schedule identical to this trigger's schedule.
 * 
 * @see #getTriggerBuilder()
 */
@Override
public ScheduleBuilder<CronTrigger> getScheduleBuilder() {
    
    CronScheduleBuilder cb = CronScheduleBuilder.cronSchedule(getCronExpression())
            .inTimeZone(getTimeZone());
        
    switch(getMisfireInstruction()) {
        case MISFIRE_INSTRUCTION_DO_NOTHING : cb.withMisfireHandlingInstructionDoNothing();
        break;
        case MISFIRE_INSTRUCTION_FIRE_ONCE_NOW : cb.withMisfireHandlingInstructionFireAndProceed();
        break;
    }
    
    return cb;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:22,代碼來源:CronTriggerImpl.java

示例8: addJobTrigger

import org.quartz.CronScheduleBuilder; //導入依賴的package包/類
@Transactional
@Override
public boolean addJobTrigger(ScheduleJobEntity job) {
	try {
		Scheduler scheduler = schedulerFactoryBean.getScheduler();
		// 表達式調度構建器
		CronScheduleBuilder scheduleBuilder = CronScheduleBuilder
				.cronSchedule(job.getCronExpression());
		// 按新的cronExpression表達式構建一個新的trigger
		CronTrigger trigger = newTrigger()
				.forJob(job.getJobKey()) //綁定job
				.withIdentity(job.getTriggerKey())
				.startAt(job.getStartDate()) // job開始日期
				.endAt(job.getEndDate())// job結束日期
				.withSchedule(scheduleBuilder).build();
		// 將trigger添加到quartz的scheduler容器
		scheduler.scheduleJob(trigger);
		return Boolean.TRUE;
	} catch (SchedulerException e) {
		throw new ServiceException(e);
	}
}
 
開發者ID:wjggwm,項目名稱:webside,代碼行數:23,代碼來源:ScheduleJobServiceImpl.java

示例9: serverTasks

import org.quartz.CronScheduleBuilder; //導入依賴的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);
	
}
 
開發者ID:Xvms,項目名稱:xvms,代碼行數:27,代碼來源:serverTasks.java

示例10: convert

import org.quartz.CronScheduleBuilder; //導入依賴的package包/類
@Override
public Trigger convert(Cron trigger) {
    CronScheduleBuilder schedule = cronSchedule(trigger.getCronExpression());
    if (trigger.getMisfireInstruction() == Cron.MisfireInstruction.DROP) {
        schedule.withMisfireHandlingInstructionDoNothing();
    } else if (trigger.getMisfireInstruction() == Cron.MisfireInstruction.FIRE_ONCE) {
        schedule.withMisfireHandlingInstructionFireAndProceed();
    }

    return newTrigger()
            .forJob(trigger.getJobKey().getName(), trigger.getJobKey().getGroup())
            .withDescription(trigger.getDescription())
            .withIdentity(trigger.getTriggerKey().getName(), trigger.getTriggerKey().getGroup())
            .withSchedule(schedule)
            .usingJobData(new JobDataMap(trigger.getTriggerData()))
            .build();
}
 
開發者ID:taboola,項目名稱:taboola-cronyx,代碼行數:18,代碼來源:CronConverter.java

示例11: addJob

import org.quartz.CronScheduleBuilder; //導入依賴的package包/類
private void addJob(ScheduleJob scheduleJob) throws Exception{  
  	checkNotNull(scheduleJob);
Preconditions.checkNotNull(StringUtils.isEmpty(scheduleJob.getCronExpression()), "CronExpression is null");

      TriggerKey triggerKey = TriggerKey.triggerKey(scheduleJob.getJobName(), scheduleJob.getJobGroup());  
      CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);  
      if(trigger != null){  
          throw new Exception("job already exists!");  
      }
      
      // simulate job info db persist operation
      scheduleJob.setJobId(String.valueOf(QuartzJobFactory.jobList.size()+1));
      QuartzJobFactory.jobList.add(scheduleJob);
      
      JobDetail jobDetail = JobBuilder.newJob(QuartzJobFactory.class).withIdentity(scheduleJob.getJobName(),scheduleJob.getJobGroup()).build();  
      jobDetail.getJobDataMap().put("scheduleJob", scheduleJob);  

      CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCronExpression());  
      trigger = TriggerBuilder.newTrigger().withIdentity(scheduleJob.getJobName(), scheduleJob.getJobGroup()).withSchedule(cronScheduleBuilder).build();  

      scheduler.scheduleJob(jobDetail, trigger);  

  }
 
開發者ID:jiwenxing,項目名稱:springboot-quartz,代碼行數:24,代碼來源:ScheduleJobService.java

示例12: prvateAddQuartz

import org.quartz.CronScheduleBuilder; //導入依賴的package包/類
private boolean prvateAddQuartz(Class<? extends Job> jobClass,JobKey jobKey, CronScheduleBuilder builder, SimpleScheduleBuilder repeatForever) {
	if(scheduler==null){
		init();
	}
	//創建一個任務計劃生成器	設置任務名稱與分組	創建任務計劃
	JobDetail job = JobBuilder.newJob(jobClass).withIdentity(jobKey).build();
	//創建一個觸發生成器	設置觸發器名稱與分組	設置觸發器出發條件	創建觸發器
	Trigger trigger = TriggerBuilder.newTrigger().withIdentity(jobKey.getName(),jobKey.getGroup()).withSchedule(builder==null?repeatForever:builder).build();
	try {
		scheduler.scheduleJob(job, trigger);
		outLog("添加任務計劃成功!");
		return true;
	} catch (SchedulerException e) {
		outLog("添加任務計劃失敗!");
	}
	return false;
}
 
開發者ID:zhiqiang94,項目名稱:BasicsProject,代碼行數:18,代碼來源:QuartzUtil.java

示例13: createScheduleJob

import org.quartz.CronScheduleBuilder; //導入依賴的package包/類
/**
 * 創建定時任務
 */
public static void createScheduleJob(Scheduler scheduler, ScheduleJobEntity 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(ScheduleJobEntity.JOB_PARAM_KEY, new Gson().toJson(scheduleJob));

        scheduler.scheduleJob(jobDetail, trigger);

        //暫停任務
        if(scheduleJob.getStatus() == ScheduleStatus.PAUSE.getValue()){
        	pauseJob(scheduler, scheduleJob.getJobId());
        }
    } catch (SchedulerException e) {
        throw new RRException("創建定時任務失敗", e);
    }
}
 
開發者ID:gyp220203,項目名稱:renren-msg,代碼行數:29,代碼來源:ScheduleUtils.java

示例14: createScheduleJob

import org.quartz.CronScheduleBuilder; //導入依賴的package包/類
/**
 * 創建定時任務
 */
public static void createScheduleJob(Scheduler scheduler, ScheduleJobEntity scheduleJob) {
    try {
    	//構建job信息
        JobDetail jobDetail = JobBuilder.newJob(ScheduleJob.class).withIdentity(getJobKey(scheduleJob.getJobId())).build();

        //表達式調度構建器
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCronExpression());

        //按新的cronExpression表達式構建一個新的trigger
        CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(scheduleJob.getJobId())).withSchedule(scheduleBuilder).build();

        //放入參數,運行時的方法可以獲取
        jobDetail.getJobDataMap().put(ScheduleJobEntity.JOB_PARAM_KEY, scheduleJob);
        
        scheduler.scheduleJob(jobDetail, trigger);
        
        //暫停任務
        if(scheduleJob.getStatus() == ScheduleStatus.PAUSE.getValue()){
        	pauseJob(scheduler, scheduleJob.getJobId());
        }
    } catch (SchedulerException e) {
        throw new RRException("創建定時任務失敗", e);
    }
}
 
開發者ID:lorcx,項目名稱:renren-security,代碼行數:28,代碼來源:ScheduleUtils.java

示例15: start

import org.quartz.CronScheduleBuilder; //導入依賴的package包/類
public void start(final AbstractNotifier notifier) {
    // if no interval is defined then don't start the notifier
    if (StringUtils.isNotBlank(notifier.getCronExpression())) {
        try {
            final JobDataMap jobDataMap = new JobDataMap();
            jobDataMap.put(NotifierJob.JOB_DATA_KEY_NOTIFIER, notifier);
            final JobDetail jobDetail = JobBuilder.newJob(NotifierJob.class).setJobData(jobDataMap)
                    .withIdentity("Job-" + notifier.getName()).build();
            final CronScheduleBuilder cronSchedule = CronScheduleBuilder.cronSchedule(notifier.getCronExpression())
                    .inTimeZone(TimeZone.getTimeZone("UTC"));
            final Trigger trigger = TriggerBuilder.newTrigger().withIdentity("Trigger-" + notifier.getName())
                    .withSchedule(cronSchedule).forJob(jobDetail).build();
            scheduler.scheduleJob(jobDetail, trigger);
        } catch (final SchedulerException e) {
            logger.error("Error scheduling notifier to start {}", notifier.getName(), e);
        }
    }
}
 
開發者ID:blackducksoftware,項目名稱:hub-email-extension,代碼行數:19,代碼來源:NotifierManager.java


注:本文中的org.quartz.CronScheduleBuilder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。