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


Java CronScheduleBuilder.cronSchedule方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: addJob

import org.quartz.CronScheduleBuilder; //導入方法依賴的package包/類
/** 
 * @Description: 添加一個定時任務  
 * @param jobName 任務名 
 * @param jobGroupName 任務組名 
 * @param triggerName 觸發器名  
 * @param triggerGroupName 觸發器組名 
 * @param jobClass 任務 
 * @param time 時間設置,參考quartz說明文檔 
 * 
 */  
@SuppressWarnings("unchecked")    
public static void addJob(String jobName, String jobGroupName,    
        String triggerName, String triggerGroupName, Class jobClass,    
        String time) {    
    try {    
        Scheduler sched = gSchedulerFactory.getScheduler();    
        JobDetail job = newJob(jobClass)  
                .withIdentity(jobName, jobGroupName)  
                .build();  
        // 表達式調度構建器  
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(time);  
        // 按新的cronExpression表達式構建一個新的trigger  
        Trigger trigger = TriggerBuilder  
                .newTrigger()  
                .withIdentity(triggerName, triggerGroupName)  
                        .withSchedule(scheduleBuilder).build();  
        sched.scheduleJob(job, trigger);   
        // 啟動    
        if (!sched.isShutdown()) {    
            sched.start();    
        }    
    } catch (Exception e) {    
        throw new RuntimeException(e);    
    }    
}
 
開發者ID:jeffreyning,項目名稱:nh-micro,代碼行數:36,代碼來源:MicroQuartzManager.java

示例6: scheduleCronNewJob

import org.quartz.CronScheduleBuilder; //導入方法依賴的package包/類
/**
 * 新增單個任務 Cron
 */
public void scheduleCronNewJob(ScheduleJob scheduleJob) throws SchedulerException, ClassNotFoundException {
    Scheduler scheduler = schedulerFactoryBean.getScheduler();
    TriggerKey triggerKey = TriggerKey.triggerKey(scheduleJob.getJobName(), scheduleJob.getJobGroup());
    // 獲取trigger,即在spring配置文件中定義的bean id="myTrigger"
    CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
    // 不存在,創建一個
    JobDetail jobDetail = JobBuilder.newJob((Class<? extends Job>) Class.forName(scheduleJob.getJobClass()))
            .withIdentity(scheduleJob.getJobName(), scheduleJob.getJobGroup()).withDescription(
                    scheduleJob.getDesc()).build();
    // 表達式調度構建器
    CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCronExpression());
    // 按新的cronExpression表達式構建一個新的trigger
    trigger = TriggerBuilder.newTrigger().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
    scheduler.scheduleJob(jobDetail, trigger);
}
 
開發者ID:bill1012,項目名稱:AdminEAP,代碼行數:19,代碼來源:JobServiceImpl.java

示例7: createScheduleJob

import org.quartz.CronScheduleBuilder; //導入方法依賴的package包/類
/**
 * 創建定時任務
 *
 * @param scheduler
 *            the scheduler
 * @param jobName
 *            the job name
 * @param jobGroup
 *            the job group
 * @param cronExpression
 *            the cron expression
 * @param isSync
 *            the is sync
 * @param param
 *            the param
 */
public static boolean createScheduleJob(Scheduler scheduler, String jobName, String jobGroup, String cronExpression,
		boolean isSync, Object param) {
	boolean result = false;
	// 同步或異步
	Class<? extends Job> jobClass = JobFactory.getInstance(isSync);
	// 構建job信息
	JobDetail jobDetail = JobBuilder.newJob(jobClass).withIdentity(jobName, jobGroup).build();
	// 放入參數,運行時的方法可以獲取,資料:http://www.cnblogs.com/wyqtomorrow/archive/2007/04/28/730963.html
	jobDetail.getJobDataMap().put(ScheduleJobBo.JOB_PARAM_KEY, param);
	// 表達式調度構建器
	CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression);
	// 按新的cronExpression表達式構建一個新的trigger
	CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(jobName, jobGroup).withSchedule(scheduleBuilder)
			.build();
	try {
		Date nextExexuteDate = scheduler.scheduleJob(jobDetail, trigger);// 任務創建成功,會返回下一次執行的時間
		if (nextExexuteDate != null) {
			result = true;
		}
	} catch (SchedulerException e) {
		LOG.error("創建定時任務失敗", e);
		return false;
	}
	return result;
}
 
開發者ID:amao12580,項目名稱:RSSReader,代碼行數:42,代碼來源:ScheduleJobUtils.java

示例8: updateScheduleJob

import org.quartz.CronScheduleBuilder; //導入方法依賴的package包/類
/**
 * 更新定時任務
 *
 * @param scheduler
 *            the scheduler
 * @param jobName
 *            the job name
 * @param jobGroup
 *            the job group
 * @param cronExpression
 *            the cron expression
 * @param isSync
 *            the is sync
 * @param param
 *            the param
 */
public static boolean updateScheduleJob(Scheduler scheduler, String jobName, String jobGroup, String cronExpression,
		boolean isSync, Object param) {
	boolean result = false;
	try {
		TriggerKey triggerKey = ScheduleJobUtils.getTriggerKey(jobName, jobGroup);
		// 表達式調度構建器
		CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression);
		CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
		// 按新的cronExpression表達式重新構建trigger
		trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
		// 按新的trigger重新設置job執行
		Date nextExcuteDate = scheduler.rescheduleJob(triggerKey, trigger);// 任務的下一次執行時間,更新成功會返回
		if (nextExcuteDate != null) {
			result = true;
		}
	} catch (SchedulerException e) {
		LOG.error("更新定時任務失敗", e);
		return false;
	}
	return result;
}
 
開發者ID:amao12580,項目名稱:RSSReader,代碼行數:38,代碼來源:ScheduleJobUtils.java

示例9: updateJobCron

import org.quartz.CronScheduleBuilder; //導入方法依賴的package包/類
/**
 * 更新job時間表達式
 * 
 * @param scheduleJob
 * @throws SchedulerException
 */
public void updateJobCron(ScheduleJob scheduleJob) throws SchedulerException {
	Scheduler scheduler = schedulerFactoryBean.getScheduler();
	TriggerKey triggerKey = TriggerKey.triggerKey(scheduleJob.getJobName(), scheduleJob.getJobGroup());
	CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
	CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCronExpression());
	trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
	scheduler.rescheduleJob(triggerKey, trigger);
}
 
開發者ID:handexing,項目名稱:frameworkAggregate,代碼行數:15,代碼來源:ScheduleJobService.java

示例10: loadExtendedTriggerProperties

import org.quartz.CronScheduleBuilder; //導入方法依賴的package包/類
public TriggerPropertyBundle loadExtendedTriggerProperties(Connection conn, TriggerKey triggerKey) throws SQLException {

        PreparedStatement ps = null;
        ResultSet rs = null;
        
        try {
            ps = conn.prepareStatement(Util.rtp(SELECT_CRON_TRIGGER, tablePrefix, schedNameLiteral));
            ps.setString(1, triggerKey.getName());
            ps.setString(2, triggerKey.getGroup());
            rs = ps.executeQuery();

            if (rs.next()) {
                String cronExpr = rs.getString(COL_CRON_EXPRESSION);
                String timeZoneId = rs.getString(COL_TIME_ZONE_ID);

                CronScheduleBuilder cb = CronScheduleBuilder.cronSchedule(cronExpr);
              
                if (timeZoneId != null) 
                    cb.inTimeZone(TimeZone.getTimeZone(timeZoneId));
                
                return new TriggerPropertyBundle(cb, null, null);
            }
            
            throw new IllegalStateException("No record found for selection of Trigger with key: '" + triggerKey + "' and statement: " + Util.rtp(SELECT_CRON_TRIGGER, tablePrefix, schedNameLiteral));
        } finally {
            Util.closeResultSet(rs);
            Util.closeStatement(ps);
        }
    }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:30,代碼來源:CronTriggerPersistenceDelegate.java

示例11: addJob

import org.quartz.CronScheduleBuilder; //導入方法依賴的package包/類
@Transactional
@Override
public boolean addJob(ScheduleJobEntity job) {
	try {
		Scheduler scheduler = schedulerFactoryBean.getScheduler();
		JobDetail jobDetail = job.getJobDetail();
		if(StringUtils.isEmpty(job.getTriggerGroup()))
		{
			//使用默認組名稱:DEFAULT
			job.setTriggerGroup(Scheduler.DEFAULT_GROUP);
		}
		// 存儲job
		jobDetail.getJobDataMap().put("scheduleJob", job);
		if(!StringUtils.isEmpty(job.getTriggerName())){
			// 表達式調度構建器
			CronScheduleBuilder scheduleBuilder = CronScheduleBuilder
				.cronSchedule(job.getCronExpression());
			// 按新的cronExpression表達式構建一個新的trigger
			CronTrigger trigger = newTrigger()
				.withIdentity(job.getTriggerName(),job.getTriggerGroup())
				.startAt(job.getStartDate()) // job開始日期
				.endAt(job.getEndDate())// job結束日期
				.withSchedule(scheduleBuilder).build();
			// 將job添加到quartz的scheduler容器
			scheduler.scheduleJob(jobDetail, trigger);
		}else
		{
			scheduler.addJob(jobDetail, true);
		}
		return Boolean.TRUE;
	} catch (SchedulerException e) {
		throw new ServiceException(e);
	}
}
 
開發者ID:wjggwm,項目名稱:webside,代碼行數:35,代碼來源:ScheduleJobServiceImpl.java

示例12: updateJobTrigger

import org.quartz.CronScheduleBuilder; //導入方法依賴的package包/類
@Transactional
@Override
public boolean updateJobTrigger(ScheduleJobEntity job) {
	try {
		Scheduler scheduler = schedulerFactoryBean.getScheduler();
		// 獲取觸發器標識
		TriggerKey triggerKey = job.getTriggerKey();
		CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);

		// Trigger已存在,更新相應的定時設置
		// 表達式調度構建器
		CronScheduleBuilder scheduleBuilder = CronScheduleBuilder
				.cronSchedule(job.getCronExpression());

		// 按新的cronExpression表達式重新構建trigger
		trigger = trigger.getTriggerBuilder()
				.forJob(job.getJobKey())
				.withIdentity(triggerKey)
				.startAt(job.getStartDate()) // job開始日期
				.endAt(job.getEndDate())// job結束日期
				.withSchedule(scheduleBuilder).build();
		// 按新的trigger重新設置job執行
		scheduler.rescheduleJob(triggerKey, trigger);
		return Boolean.TRUE;
	} catch (Exception e) {
		throw new ServiceException(e);
	}
}
 
開發者ID:wjggwm,項目名稱:webside,代碼行數:29,代碼來源:ScheduleJobServiceImpl.java

示例13: updateJobCronExpression

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

      TriggerKey triggerKey = TriggerKey.triggerKey(scheduleJob.getJobName(), scheduleJob.getJobGroup());  
      CronTrigger cronTrigger = (CronTrigger)scheduler.getTrigger(triggerKey);  
      CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCronExpression());  
      cronTrigger = cronTrigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(cronScheduleBuilder).build();  
      scheduler.rescheduleJob(triggerKey, cronTrigger);  
  }
 
開發者ID:jiwenxing,項目名稱:springboot-quartz,代碼行數:11,代碼來源:ScheduleJobService.java

示例14: updateScheduleJob

import org.quartz.CronScheduleBuilder; //導入方法依賴的package包/類
/**
 * 更新定時任務
 */
public static void updateScheduleJob(Scheduler scheduler, ScheduleJobEntity scheduleJob) {
    try {
        TriggerKey triggerKey = getTriggerKey(scheduleJob.getJobId());

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

        CronTrigger trigger = getCronTrigger(scheduler, scheduleJob.getJobId());
        
        //按新的cronExpression表達式重新構建trigger
        trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
        
        //參數
        trigger.getJobDataMap().put(ScheduleJobEntity.JOB_PARAM_KEY, scheduleJob);
        
        scheduler.rescheduleJob(triggerKey, trigger);
        
        //暫停任務
        if(scheduleJob.getStatus() == ScheduleStatus.PAUSE.getValue()){
        	pauseJob(scheduler, scheduleJob.getJobId());
        }
        
    } catch (SchedulerException e) {
        throw new RRException("更新定時任務失敗", e);
    }
}
 
開發者ID:lorcx,項目名稱:renren-security,代碼行數:30,代碼來源:ScheduleUtils.java

示例15: createTrigger

import org.quartz.CronScheduleBuilder; //導入方法依賴的package包/類
private CronTrigger createTrigger(final String cronExpression) {
    CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression);
    if (schedulerFacade.isMisfire()) {
        cronScheduleBuilder = cronScheduleBuilder.withMisfireHandlingInstructionFireAndProceed();
    } else {
        cronScheduleBuilder = cronScheduleBuilder.withMisfireHandlingInstructionDoNothing();
    }
    return TriggerBuilder.newTrigger()
            .withIdentity(triggerIdentity)
            .withSchedule(cronScheduleBuilder).build();
}
 
開發者ID:artoderk,項目名稱:elastic-jobx,代碼行數:12,代碼來源:JobScheduleController.java


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