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


Java SchedulerFactoryBean.setTriggers方法代碼示例

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


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

示例1: build

import org.springframework.scheduling.quartz.SchedulerFactoryBean; //導入方法依賴的package包/類
public SchedulerFactoryBean build() throws Exception {
	SchedulerFactoryBean bean = new SchedulerFactoryBean();
	PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
	propertiesFactoryBean.setLocation(new ClassPathResource(config));
	propertiesFactoryBean.afterPropertiesSet();
	Properties props = propertiesFactoryBean.getObject();
	List<Trigger> triggers = Lists.newArrayList();
	List<JobModel> jobList = getJobs(props);
	for (JobModel job : jobList) {
		if (!job.isEnable()) {
			continue;
		}
		JobDetailFactoryBean detail = createJobDetail(job.getName(), Class.forName(job.getJob()));
		CronTriggerFactoryBean trigger = createCronTrigger(job.getName(), detail.getObject(), job.getCorn());
		CronTrigger t = trigger.getObject();
		triggers.add(t);
	}
	bean.setTriggers(triggers.toArray(new Trigger[0]));
	//bean.afterPropertiesSet();
	return bean;

}
 
開發者ID:mazhaoyong,項目名稱:api-server-seed,代碼行數:23,代碼來源:QuartzFactory.java

示例2: createSchedulerFactoryBean

import org.springframework.scheduling.quartz.SchedulerFactoryBean; //導入方法依賴的package包/類
/**
 * 創建調度服務
 * 每一個批次啟動後,創建一個調度服務
 */
public SchedulerFactoryBean createSchedulerFactoryBean(BatchRunConfDto conf, ResourceManagement drm) throws Exception {
    this.conf = conf;
    this.jobKeyStatusService = drm.getJobKeyStatusService();
    this.argumentService = drm.getArgumentService();

    getAllTaskForMap();
    initGroupTaskMap(drm.getJobKeyList());

    SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
    // 配置DataSource後,將會出現異常
    // JobLauncher實例化對象無法序列化
    // schedulerFactoryBean.setDataSource(dataSource);
    schedulerFactoryBean.setSchedulerName(conf.getBatchId());
    schedulerFactoryBean.setWaitForJobsToCompleteOnShutdown(true);
    schedulerFactoryBean.setAutoStartup(false);

    // 獲取指定批次的所有任務Job
    ArrayList<SimpleTrigger> arrayList = new ArrayList<SimpleTrigger>();
    for (String jobId : jobKeyStatusService.getAllJob().keySet()) {
        SimpleTrigger simpleTrigger = createSimpleTrigger(jobId);
        schedulerFactoryBean.setTriggers(simpleTrigger);
        arrayList.add(simpleTrigger);
    }

    SimpleTrigger[] simpleTriggers = new SimpleTrigger[arrayList.size()];
    for (int i = 0; i < arrayList.size(); i++) {
        simpleTriggers[i] = arrayList.get(i);
    }
    schedulerFactoryBean.setTriggers(simpleTriggers);
    schedulerFactoryBean.afterPropertiesSet();
    schedulerFactoryBean.getScheduler().pauseAll();
    schedulerFactoryBean.start();
    return schedulerFactoryBean;
}
 
開發者ID:hzwy23,項目名稱:batch-scheduler,代碼行數:39,代碼來源:BatchSchedulerConfig.java

示例3: schedulerFactory

import org.springframework.scheduling.quartz.SchedulerFactoryBean; //導入方法依賴的package包/類
/** 
 * attention: 
 * Details:定義quartz調度工廠 
 */  
@Bean(name = "scheduler")  
public SchedulerFactoryBean schedulerFactory(Trigger cronJobTrigger) {  
    SchedulerFactoryBean bean = new SchedulerFactoryBean();  
    // 用於quartz集群,QuartzScheduler 啟動時更新己存在的Job  
    bean.setOverwriteExistingJobs(true);  
    // 延時啟動,應用啟動1秒後  
    bean.setStartupDelay(1);  
    // 注冊觸發器  
    bean.setTriggers(cronJobTrigger);  
    return bean;  
}
 
開發者ID:duanyaxin,項目名稱:springboot-smart,代碼行數:16,代碼來源:QuartzConfigration.java

示例4: getEventHealthMonitorBean

import org.springframework.scheduling.quartz.SchedulerFactoryBean; //導入方法依賴的package包/類
@Bean
public SchedulerFactoryBean getEventHealthMonitorBean(){
	SchedulerFactoryBean bean = new SchedulerFactoryBean();
	bean.setBeanName("EventHealthMonitorThread");
	bean.setTriggers(new Trigger [] {getMonitorJobTrigger().getObject()});
	Properties prop = new Properties();
	prop.setProperty("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
	prop.setProperty("org.quartz.threadPool.threadCount", "1");
	bean.setQuartzProperties(prop);
	return bean;
}
 
開發者ID:gagoyal01,項目名稱:mongodb-rdbms-sync,代碼行數:12,代碼來源:MvcConfiguration.java

示例5: getEventJobBean

import org.springframework.scheduling.quartz.SchedulerFactoryBean; //導入方法依賴的package包/類
@Bean
public SchedulerFactoryBean getEventJobBean(){
	SchedulerFactoryBean bean = new SchedulerFactoryBean();
	bean.setBeanName("EligibleEventProcessorThread");
	bean.setTriggers(new Trigger [] {getEventJobTrigger().getObject()});
	Properties prop = new Properties();
	prop.setProperty("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
	prop.setProperty("org.quartz.threadPool.threadCount", "1");
	bean.setQuartzProperties(prop);
	return bean;
}
 
開發者ID:gagoyal01,項目名稱:mongodb-rdbms-sync,代碼行數:12,代碼來源:MvcConfiguration.java

示例6: getSchedulerFactoryBean

import org.springframework.scheduling.quartz.SchedulerFactoryBean; //導入方法依賴的package包/類
/**
 * Gets the scheduler factory bean.
 *
 * @param appStatsTrigger the app stats trigger
 * @param clusterStatsTrigger the cluster stats trigger
 * @param connectorStatsTrigger the connector stats trigger
 * @param datasourceStatsTrigger the datasource stats trigger
 * @param memoryStatsTrigger the memory stats trigger
 * @param runtimeStatsTrigger the runtime stats trigger
 * @param statsSerializerTrigger the stats serializer trigger
 * @return the scheduler factory bean
 */
@Bean(name = "scheduler")
public SchedulerFactoryBean getSchedulerFactoryBean(@Autowired AppStatsTrigger appStatsTrigger,
    @Autowired ClusterStatsTrigger clusterStatsTrigger,
    @Autowired ConnectorStatsTrigger connectorStatsTrigger,
    @Autowired DatasourceStatsTrigger datasourceStatsTrigger,
    @Autowired MemoryStatsTrigger memoryStatsTrigger,
    @Autowired RuntimeStatsTrigger runtimeStatsTrigger,
    @Autowired StatsSerializerTrigger statsSerializerTrigger) {

  logger.debug("Instantiated scheduler");
  SchedulerFactoryBean bean = new SchedulerFactoryBean();

  // Add Triggers
  bean.setTriggers(appStatsTrigger.getObject(), clusterStatsTrigger.getObject(),
      connectorStatsTrigger.getObject(), datasourceStatsTrigger.getObject(),
      memoryStatsTrigger.getObject(), runtimeStatsTrigger.getObject(),
      statsSerializerTrigger.getObject());

  // Add Properties
  Properties properties = new Properties();
  properties.setProperty("org.quartz.scheduler.instanceName", "ProbeScheduler");
  properties.setProperty("org.quartz.threadPool.threadCount", "5");
  properties.setProperty("org.quartz.threadPool.threadNamePrefix", "Probe_Quartz");
  bean.setQuartzProperties(properties);

  return bean;
}
 
開發者ID:psi-probe,項目名稱:psi-probe,代碼行數:40,代碼來源:ProbeConfig.java

示例7: scheduler

import org.springframework.scheduling.quartz.SchedulerFactoryBean; //導入方法依賴的package包/類
@Bean
public Scheduler scheduler() throws Exception {
	SchedulerFactoryBean factory = new SchedulerFactoryBean();
	factory.setTriggers(new Trigger[] { jobDetailTrigger() });
	factory.setJobFactory(new SpringBeanJobFactory());
	factory.setDataSource(dataSource());
	factory.setSchedulerContextAsMap(new HashMap<String, Object>() {{
		put("job", job());
		put("jobLauncher", jobLauncher);
	}});
	factory.afterPropertiesSet();

	return factory.getObject();
}
 
開發者ID:debop,項目名稱:spring-batch-experiments,代碼行數:15,代碼來源:QuartzSchedulingConfiguration.java

示例8: autoSchedulerFactory

import org.springframework.scheduling.quartz.SchedulerFactoryBean; //導入方法依賴的package包/類
@Bean(name = QUARTZ_SCHEDULER_FACTORY_BEAN_NAME)
@ConditionalOnMissingBean(name = QUARTZ_SCHEDULER_FACTORY_BEAN_NAME)
public SchedulerFactoryBean autoSchedulerFactory(ApplicationContext applicationContext, JobFactory jobFactory,
		QuartzSchedulerProperties properties, @Qualifier(QUARTZ_PROPERTIES_BEAN_NAME) Properties quartzProperties) {
	
	LOGGER.debug("creating SchedulerFactory");
	
	SchedulerFactoryBean factory = BeanUtils.instantiateClass(SchedulerFactoryBean.class);
	
       factory.setApplicationContext(applicationContext);
       factory.setJobFactory(jobFactory);
       
       Persistence persistenceSettings = properties.getPersistence();
       if (persistenceSettings.isPersisted()) {
       	factory.setDataSource(getDataSource(applicationContext, persistenceSettings));
       	if (persistenceSettings.isUsePlatformTxManager()) {
       		PlatformTransactionManager txManager = getTransactionManager(applicationContext);
           	if (null != txManager) {
               	factory.setTransactionManager(txManager);
               }
       	}
       }
       
       SchedulerFactory factorySettings = properties.getSchedulerFactory();
       factory.setSchedulerName(factorySettings.getSchedulerName());
       factory.setPhase(factorySettings.getPhase());
       factory.setStartupDelay(factorySettings.getStartupDelay());
       factory.setAutoStartup(factorySettings.isAutoStartup());
       factory.setWaitForJobsToCompleteOnShutdown(factorySettings.isWaitForJobsToCompleteOnShutdown());
       factory.setOverwriteExistingJobs(factorySettings.isOverwriteExistingJobs());
       factory.setExposeSchedulerInRepository(factorySettings.isExposeSchedulerInRepository());
       
       factory.setQuartzProperties(quartzProperties);
       
       Collection<Trigger> triggers = getTriggers(applicationContext);
       if (null != triggers && !triggers.isEmpty()) {
       	factory.setTriggers(triggers.toArray(new Trigger[triggers.size()]));
       	LOGGER.info("staring scheduler factory with " + triggers.size() + " job triggers");
       } else {
       	LOGGER.info("staring scheduler factory with 0 job triggers");
       }
       
       QuartzSchedulerFactoryOverrideHook hook = getQuartzSchedulerFactoryOverrideHook(applicationContext);
       if (null != hook) {
       	factory = hook.override(factory, properties, quartzProperties);
       }
       
	return factory;
}
 
開發者ID:andrehertwig,項目名稱:spring-boot-starter-quartz,代碼行數:50,代碼來源:QuartzSchedulerAutoConfiguration.java

示例9: start

import org.springframework.scheduling.quartz.SchedulerFactoryBean; //導入方法依賴的package包/類
public void start() throws Exception {
	LOG.info("start crontab");
	
	if (application.getCrontab() != null && application.getCrontab().getCrons() != null) {
		
		Trigger[] triggers = new Trigger[application.getCrontab().getCrons().size()];
		for (int i = 0; i < triggers.length; i ++) {
			
			Cron cron = application.getCrontab().getCrons().get(i);
			String desc = cron.getDescription();
			String exp = cron.getSchedule();
			String script = cron.getScript();
			
			MethodInvokingJobDetailFactoryBean jobDetailFactory = new MethodInvokingJobDetailFactoryBean();
			jobDetailFactory.setBeanName("jobDetail" + script);
			jobDetailFactory.setName("jobDetail" + script);
			jobDetailFactory.setTargetObject(this);
			jobDetailFactory.setTargetMethod("execute");
			jobDetailFactory.setArguments(new Object[]{script, exp, desc});
			jobDetailFactory.setConcurrent(application.getCrontab().isConcurrent());
			jobDetailFactory.afterPropertiesSet();
			
			JobDetail jobDetail = jobDetailFactory.getObject();

			CronTriggerBean trigger = new CronTriggerBean();
			trigger.setBeanName("trigger" + script);
			trigger.setName("trigger" + script);
			trigger.setJobDetail(jobDetail);
			trigger.setCronExpression(exp);
			trigger.afterPropertiesSet();
			
			triggers[i] = trigger;
		}

		Properties properties = new Properties();
		properties.setProperty("org.quartz.scheduler.skipUpdateCheck", "true");
		
		schedulerFactory = new SchedulerFactoryBean();
		schedulerFactory.setBeanName("schedulerFactory");
		schedulerFactory.setTriggers(triggers);
		schedulerFactory.setQuartzProperties(properties);
		//schedulerFactory.setAutoStartup(true);
		schedulerFactory.afterPropertiesSet();
		schedulerFactory.start();
	}
}
 
開發者ID:lane-cn,項目名稱:getty,代碼行數:47,代碼來源:CrontabManager.java


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