当前位置: 首页>>代码示例>>Java>>正文


Java Scheduler.scheduleJob方法代码示例

本文整理汇总了Java中org.quartz.Scheduler.scheduleJob方法的典型用法代码示例。如果您正苦于以下问题:Java Scheduler.scheduleJob方法的具体用法?Java Scheduler.scheduleJob怎么用?Java Scheduler.scheduleJob使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.quartz.Scheduler的用法示例。


在下文中一共展示了Scheduler.scheduleJob方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: refreshMetadata

import org.quartz.Scheduler; //导入方法依赖的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: addJobTrigger

import org.quartz.Scheduler; //导入方法依赖的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: addSchedule

import org.quartz.Scheduler; //导入方法依赖的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: createScheduleJob

import org.quartz.Scheduler; //导入方法依赖的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

示例5: register

import org.quartz.Scheduler; //导入方法依赖的package包/类
/**
 * Register with teh scheduler.
 * 
 * @param scheduler Scheduler
 * @throws SchedulerException 
 */
public void register(Scheduler scheduler) throws SchedulerException
{
    JobDetail jobDetail = getJobDetail();
    Trigger trigger = getTrigger();

    if (s_logger.isDebugEnabled())
    {
        s_logger.debug(("Registering job: " + jobDetail));
        s_logger.debug(("With trigger: " + trigger));
    }
    scheduler.scheduleJob(jobDetail, trigger);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:19,代码来源:AbstractScheduledAction.java

示例6: executeScheduleJob

import org.quartz.Scheduler; //导入方法依赖的package包/类
/**
 * 执行计划任务
 * @param job
 * @param trigger
 * @return
 * @throws SchedulerException
 */
public static ScheduleJobResult executeScheduleJob(JobDetail job, Trigger trigger) throws SchedulerException {
    ScheduleJobResult scheduleJobResult = new ScheduleJobResult();
    //判断是否满足计划任务的创建条件
    if(job.getKey() == null || trigger.getKey() == null || job.getJobDataMap() == null){
        scheduleJobResult.setScheduleJobStatus(ScheduleJobStatus.FAILED);
        //不满足计划任务的创建条件,返回scheduleJobResult值类
        return scheduleJobResult;
    }
    scheduleJobResult.setJobDetail(job);
    scheduleJobResult.setTrigger(trigger);
    //开始分配计划任务
    Scheduler scheduler  = SchedulerFactory.getScheduler();
    //开始判断是否存在相同的计划任务
    if(scheduler.checkExists(job.getKey())){
        log.info("存在相同的计划任务:{}",job.getKey());
        scheduler.deleteJob(job.getKey());
        scheduleJobResult.setJobKey(job.getKey());
        scheduleJobResult.setTriggerKey(trigger.getKey());
        scheduleJobResult.setScheduleJobStatus(ScheduleJobStatus.ISEXIST);
        scheduler.scheduleJob(job,trigger);
        scheduler.start();
    }else{
        scheduler.scheduleJob(job,trigger);
        scheduler.start();
        scheduleJobResult.setJobKey(job.getKey());
        scheduleJobResult.setTriggerKey(trigger.getKey());
        scheduleJobResult.setScheduleJobStatus(ScheduleJobStatus.SUCCESS);
    }
    //计划任务分配成功
    return scheduleJobResult;
}
 
开发者ID:DevopsJK,项目名称:SuitAgent,代码行数:39,代码来源:SchedulerUtil.java

示例7: execute

import org.quartz.Scheduler; //导入方法依赖的package包/类
@Override
public void execute(final WebScriptRequest request, final WebScriptResponse response) throws IOException {

	final Writer w = response.getWriter();
	String siteId = request.getParameter(PARAM_SITE_ID);
	String role = siteService.getMembersRole(siteId, authenticationService.getCurrentUserName());
	if (authorityService.hasAdminAuthority() || SiteModel.SITE_MANAGER.equals(role)) {

		log.debug("Starting job manually. jobdetailbean=" + jobdetailbean);
		SchedulerFactory schedFact = new StdSchedulerFactory();

		// Create a trigger that fires exactly once, ten seconds from now
		final long startTime = System.currentTimeMillis() + 1000L;
		final SimpleTrigger trigger = new SimpleTrigger("manualTrigger", null, new Date(startTime), null, 0, 0L);

		try {
			final Scheduler s = schedFact.getScheduler();
			s.addJobListener(new ManualJobListener());
			log.debug("trigger: " + trigger + ", scheduler: " + s);

			s.scheduleJob(jobdetailbean, trigger);
			s.start();

			String msgStart = "LDAP Sync triggered at " + new Date(startTime);
			log.info(msgStart);
			w.write(msgStart);

		} catch (final Exception e) {
			log.error("Error while executing " + jobdetailbean + " manually");
			throw new AlfrescoRuntimeException("Error while executing " + jobdetailbean + " manually", e);
		}

	} else {
		String msg = "Only Alfresco Administrators or SiteManagers can trigger ldpa sync action manually.";
		log.error(msg);
		throw new AlfrescoRuntimeException(msg);
	}
}
 
开发者ID:form4,项目名称:alfresco-triggerauthenticationsync,代码行数:39,代码来源:StartPeopleSyncWebScript.java

示例8: scheduleCronJob

import org.quartz.Scheduler; //导入方法依赖的package包/类
/**
 * Schedule a job by jobName at given date.
 */
@Override
public boolean scheduleCronJob(String jobName, Class<? extends QuartzJobBean> jobClass, Date date, String cronExpression) {
	System.out.println("Request received to scheduleJob");

	String jobKey = jobName;
	String groupKey = "SampleGroup";	
	String triggerKey = jobName;		

	JobDetail jobDetail = JobUtil.createJob(jobClass, false, context, jobKey, groupKey);

	System.out.println("creating trigger for key :"+jobKey + " at date :"+date);
	Trigger cronTriggerBean = JobUtil.createCronTrigger(triggerKey, date, cronExpression, SimpleTrigger.MISFIRE_INSTRUCTION_FIRE_NOW);

	try {
		Scheduler scheduler = schedulerFactoryBean.getScheduler();
		Date dt = scheduler.scheduleJob(jobDetail, cronTriggerBean);
		System.out.println("Job with key jobKey :"+jobKey+ " and group :"+groupKey+ " scheduled successfully for date :"+dt);
		return true;
	} catch (SchedulerException e) {
		System.out.println("SchedulerException while scheduling job with key :"+jobKey + " message :"+e.getMessage());
		e.printStackTrace();
	}

	return false;
}
 
开发者ID:javabypatel,项目名称:spring-boot-quartz-demo,代码行数:29,代码来源:JobServiceImpl.java

示例9: addJob

import org.quartz.Scheduler; //导入方法依赖的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

示例10: main

import org.quartz.Scheduler; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
  // create the parser
  CommandLineParser parser = new DefaultParser();
  CommandLine line = parser.parse(getOptions(), args);

  // files directory
  String directory = line.getOptionValue("directory", "hkex/");

  // config file
  String config = line.getOptionValue("config", "config/tracker.properties");

  // init scheduler
  SchedulerFactory sf = new StdSchedulerFactory();
  Scheduler scheduler = sf.getScheduler();

  // define job instance
  JobDetail job = newJob(TrackerJob.class)
      .withIdentity("job", "group")
      .usingJobData("directory", directory)
      .usingJobData("config", config)
      .build();

  // define trigger instance
  Trigger trigger = newTrigger()
      .withIdentity("trigger", "group")
      .startNow()
      .withSchedule(dailyAtHourAndMinute(8, 30)) // fire every day at 8:30
      .build();

  // schedule the job with the trigger
  scheduler.scheduleJob(job, trigger);

  // start scheduler
  scheduler.start();
}
 
开发者ID:longkerdandy,项目名称:qfii-tracker,代码行数:36,代码来源:ScheduleService.java

示例11: startScheduler

import org.quartz.Scheduler; //导入方法依赖的package包/类
private void startScheduler() throws SchedulerException {
      log.warn("Starting scheduler (pid:" + ServerUtil.getCurrentPid() + ")");
      Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
      scheduler.start();

      JobDataMap jobDataMap = new JobDataMap();
      jobDataMap.put(ApiFactoryService.class.getName(), this.apiFactoryService);
      jobDataMap.put(DistributedApplianceConformJobFactory.class.getName(), this.daConformJobFactory);
      jobDataMap.put(DeploymentSpecConformJobFactory.class.getName(), this.dsConformJobFactory);
      jobDataMap.put(SecurityGroupConformJobFactory.class.getName(), this.sgConformJobFactory);
      jobDataMap.put(ManagerConnectorConformJobFactory.class.getName(), this.mcConformJobFactory);


      JobDetail syncDaJob = JobBuilder.newJob(SyncDistributedApplianceJob.class).usingJobData(jobDataMap).build();
      JobDetail syncSgJob = JobBuilder.newJob(SyncSecurityGroupJob.class).usingJobData(jobDataMap).build();

// TODO: Remove the delay, once plugin state listener is implemented.
      // Related issue: https://github.com/opensecuritycontroller/osc-core/issues/545
Trigger syncDaJobTrigger = TriggerBuilder.newTrigger()
		.startAt(Date.from(Instant.now().plusSeconds(SERVER_SYNC_DELAY))).withSchedule(SimpleScheduleBuilder
		.simpleSchedule().withIntervalInMinutes(this.scheduledSyncInterval).repeatForever()).build();

Trigger syncSgJobTrigger = TriggerBuilder.newTrigger()
		.startAt(Date.from(Instant.now().plusSeconds(SERVER_SYNC_DELAY))).withSchedule(SimpleScheduleBuilder
		.simpleSchedule().withIntervalInMinutes(this.scheduledSyncInterval).repeatForever()).build();

      scheduler.scheduleJob(syncDaJob, syncDaJobTrigger);
      scheduler.scheduleJob(syncSgJob, syncSgJobTrigger);

      this.archiveService.maybeScheduleArchiveJob();
  }
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:32,代码来源:Server.java

示例12: addJob

import org.quartz.Scheduler; //导入方法依赖的package包/类
/** 
 * @Description: 添加一个定时任务,使用默认的任务组名,触发器名,触发器组名 
 * @param jobName 任务名 
 * @param cls 任务 
 * @param time 时间设置,参考quartz说明文档  
 * 
 */  
@SuppressWarnings("unchecked")    
public static void addJob(String jobName, Class cls, String cron,String groovyName,String groovyMethod,String paramStr) {    
    try {    
        Scheduler sched = gSchedulerFactory.getScheduler();    
        JobDetail job = newJob(cls)  
                .withIdentity(jobName, JOB_GROUP_NAME)  
                .build();  
        // 添加具体任务方法  
        job.getJobDataMap().put("groovyName", groovyName);  
        job.getJobDataMap().put("groovyMethod", groovyMethod);
        job.getJobDataMap().put("paramStr", paramStr);
        
        // 表达式调度构建器  
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cron);  
        // 按新的cronExpression表达式构建一个新的trigger  
        Trigger trigger = TriggerBuilder  
                .newTrigger()  
                .withIdentity(jobName, TRIGGER_GROUP_NAME)  
                        .withSchedule(scheduleBuilder).build();  
  
        //交给scheduler去调度  
        sched.scheduleJob(job, trigger);  
          
        // 启动    
        if (!sched.isShutdown()) {    
            sched.start();    
        }    
    } catch (Exception e) {    
        throw new RuntimeException(e);    
    }    
}
 
开发者ID:jeffreyning,项目名称:nh-micro,代码行数:39,代码来源:MicroQuartzManager.java

示例13: initSystemJobs

import org.quartz.Scheduler; //导入方法依赖的package包/类
public void initSystemJobs() throws Exception{
	Scheduler scheduler=schedulerService.retrieveScheduler();
	for(ISystemJobProvider provider:systemJobProviders){
		scheduler.scheduleJob(provider.getJobDetail(), provider.getTrigger());			
	}			
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:7,代码来源:Initializer.java

示例14: addTriggerForJob

import org.quartz.Scheduler; //导入方法依赖的package包/类
public void addTriggerForJob(String schedulerName, JobDetail jobDetail, Trigger trigger) throws SchedulerException {
    Scheduler scheduler = this.getAssertScheduler(schedulerName);
    scheduler.scheduleJob(jobDetail, trigger);
}
 
开发者ID:quartzweb,项目名称:quartz-web,代码行数:5,代码来源:QuartzManager.java

示例15: addTrigger

import org.quartz.Scheduler; //导入方法依赖的package包/类
public static void addTrigger(Scheduler scheduler, JobDetail jobDetail, Trigger trigger) throws SchedulerException {
    scheduler.scheduleJob(jobDetail, trigger);
}
 
开发者ID:quartzweb,项目名称:quartz-web,代码行数:4,代码来源:QuartzUtils.java


注:本文中的org.quartz.Scheduler.scheduleJob方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。