当前位置: 首页>>代码示例>>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;未经允许,请勿转载。