當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。