本文整理匯總了Java中org.springframework.scheduling.quartz.SchedulerFactoryBean類的典型用法代碼示例。如果您正苦於以下問題:Java SchedulerFactoryBean類的具體用法?Java SchedulerFactoryBean怎麽用?Java SchedulerFactoryBean使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SchedulerFactoryBean類屬於org.springframework.scheduling.quartz包,在下文中一共展示了SchedulerFactoryBean類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: schedulerFactory
import org.springframework.scheduling.quartz.SchedulerFactoryBean; //導入依賴的package包/類
@Bean
public SchedulerFactoryBean schedulerFactory(JobFactory jobFactory) {
SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
schedulerFactoryBean.setApplicationContext(applicationContext);
schedulerFactoryBean.setAutoStartup(schedulerProperties.isAutoStartup());
schedulerFactoryBean.setDataSource(dataSource);
schedulerFactoryBean.setTransactionManager(platformTransactionManager);
schedulerFactoryBean.setOverwriteExistingJobs(schedulerProperties.isOverwriteExistingJobs());
schedulerFactoryBean.setSchedulerFactoryClass(StdSchedulerFactory.class);
schedulerFactoryBean.setBeanName(schedulerProperties.getBeanName());
schedulerFactoryBean.setJobFactory(jobFactory);
schedulerFactoryBean.setWaitForJobsToCompleteOnShutdown(schedulerProperties.isWaitOnShutdown());
schedulerFactoryBean.setQuartzProperties(schedulerProperties.getProperties());
schedulerFactoryBean.setStartupDelay(schedulerProperties.getStartupDelay());
schedulerFactoryBean.setCalendars(calendarMap);
schedulerFactoryBean.setSchedulerListeners(schedulerListeners);
return schedulerFactoryBean;
}
示例2: schedulerFactoryBean
import org.springframework.scheduling.quartz.SchedulerFactoryBean; //導入依賴的package包/類
@Bean
public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource) {
SchedulerFactoryBean factory = new SchedulerFactoryBean();
factory.setDataSource(dataSource);
//quartz參數
Properties prop = new Properties();
prop.put("org.quartz.scheduler.instanceName", "RenrenScheduler");
prop.put("org.quartz.scheduler.instanceId", "AUTO");
//線程池配置
prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
prop.put("org.quartz.threadPool.threadCount", "20");
prop.put("org.quartz.threadPool.threadPriority", "5");
//JobStore配置
prop.put("org.quartz.jobStore.class", "org.quartz.impl.jdbcjobstore.JobStoreTX");
//集群配置
// prop.put("org.quartz.jobStore.isClustered", "true");
// prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000");
// prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1");
prop.put("org.quartz.jobStore.misfireThreshold", "12000");
prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_");
factory.setQuartzProperties(prop);
factory.setSchedulerName("RenrenScheduler");
//延時啟動
factory.setStartupDelay(30);
factory.setApplicationContextSchedulerContextKey("applicationContextKey");
//可選,QuartzScheduler 啟動時更新己存在的Job,這樣就不用每次修改targetObject後刪除qrtz_job_details表對應記錄了
factory.setOverwriteExistingJobs(true);
//設置自動啟動,默認為true
factory.setAutoStartup(true);
return factory;
}
示例3: schedulerFactoryBean
import org.springframework.scheduling.quartz.SchedulerFactoryBean; //導入依賴的package包/類
/**
* create scheduler
*/
@Bean
public SchedulerFactoryBean schedulerFactoryBean() throws IOException {
SchedulerFactoryBean factory = new SchedulerFactoryBean();
factory.setOverwriteExistingJobs(true);
factory.setDataSource(dataSource);
factory.setQuartzProperties(quartzProperties());
//Register listeners to get notification on Trigger misfire etc
factory.setGlobalTriggerListeners(triggerListner);
factory.setGlobalJobListeners(jobsListener);
AutowiringSpringBeanJobFactory jobFactory = new AutowiringSpringBeanJobFactory();
jobFactory.setApplicationContext(applicationContext);
factory.setJobFactory(jobFactory);
return factory;
}
示例4: schedulerFactoryBean
import org.springframework.scheduling.quartz.SchedulerFactoryBean; //導入依賴的package包/類
@Bean(name = "batch")
public SchedulerFactoryBean schedulerFactoryBean(
DataSource dataSource,
JobFactory jobFactory) {
SchedulerFactoryBean factory = new SchedulerFactoryBean();
factory.setOverwriteExistingJobs(true);
factory.setDataSource(dataSource);
factory.setJobFactory(jobFactory);
Properties props = new Properties();
props.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, "batch");
props.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_ID, "auto");
props.setProperty("org.quartz.jobStore.driverDelegateClass", "org.quartz.impl.jdbcjobstore.HSQLDBDelegate");
props.setProperty("org.quartz.scheduler.skipUpdateCheck", "true");
// factory.setQuartzProperties(props);
// factory.setTriggers(sampleJobTrigger);
return factory;
}
示例5: schedulerFactoryBean
import org.springframework.scheduling.quartz.SchedulerFactoryBean; //導入依賴的package包/類
@Bean
public SchedulerFactoryBean schedulerFactoryBean(
DataSource dataSource, PlatformTransactionManager transactionManager, JobFactory jobFactory) {
final SchedulerFactoryBean factory = new SchedulerFactoryBean();
factory.setOverwriteExistingJobs(true);
factory.setTaskExecutor(commonTaskScheduler.getScheduledExecutor());
factory.setDataSource(dataSource);
factory.setTransactionManager(transactionManager);
factory.setJobFactory(jobFactory);
factory.setQuartzProperties(quartzProperties);
factory.setSchedulerName(SCHEDULER_NAME);
factory.setAutoStartup(true);
factory.setWaitForJobsToCompleteOnShutdown(true);
// Delay added to avoid errors caused by updating registered tasks and reduce load on startup
factory.setStartupDelay(30);
return factory;
}
示例6: 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;
}
示例7: schedulerFactory
import org.springframework.scheduling.quartz.SchedulerFactoryBean; //導入依賴的package包/類
@Bean
public SchedulerFactoryBean schedulerFactory(JobFactory jobFactory) throws IOException {
SchedulerFactoryBean factory = new SchedulerFactoryBean();
factory.setSchedulerName("Sentry");
factory.setJobFactory(jobFactory);
factory.setQuartzProperties(quartzProperties());
// this allows to update triggers in DB when updating settings in config file:
factory.setOverwriteExistingJobs(true);
return factory;
}
示例8: getApplicationContext
import org.springframework.scheduling.quartz.SchedulerFactoryBean; //導入依賴的package包/類
private WebApplicationContext getApplicationContext() {
if (context == null) {
String _step = step; //preserve step
step = "Shutdown schedulers";
Long lngId = (long)cfg.getDefaultLangId();
context = ApplicationHelper.getApplicationContext(lngId);
SchedulerFactoryBean sfb = context.getBean(SchedulerFactoryBean.class);
try {
sfb.getScheduler().shutdown(false);
step = _step; //restore
} catch (Exception e) {
handleError(e);
}
}
return context;
}
示例9: schedulerFactoryBean
import org.springframework.scheduling.quartz.SchedulerFactoryBean; //導入依賴的package包/類
@Bean
public SchedulerFactoryBean schedulerFactoryBean(ApplicationContext applicationContext, DataSource dataSource,
JobFactory jobFactory)
{
SchedulerFactoryBean schedulerFactory = new SchedulerFactoryBean();
schedulerFactory.setConfigLocation(new ClassPathResource("quartz.properties"));
schedulerFactory.setAutoStartup(true);
schedulerFactory.setDataSource(dataSource);
schedulerFactory.setJobFactory(jobFactory);
return schedulerFactory;
}
示例10: schedule
import org.springframework.scheduling.quartz.SchedulerFactoryBean; //導入依賴的package包/類
public static void schedule(final SchedulerFactoryBean scheduler, final Map<String, Object> jobMap) {
@SuppressWarnings("unchecked")
AfterHandlingJob jobInstance = (AfterHandlingJob) ApplicationContextProvider.getBeanFactory().
createBean(AfterHandlingJob.class, AbstractBeanDefinition.AUTOWIRE_BY_TYPE, false);
String jobName = AfterHandlingJob.class.getName() + UUID.randomUUID();
jobMap.put(JobManager.DOMAIN_KEY, AuthContextUtils.getDomain());
ApplicationContextProvider.getBeanFactory().registerSingleton(jobName, jobInstance);
JobBuilder jobDetailBuilder = JobBuilder.newJob(AfterHandlingJob.class).
withIdentity(jobName).
usingJobData(new JobDataMap(jobMap));
TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger().
withIdentity(JobNamer.getTriggerName(jobName)).
startNow();
try {
scheduler.getScheduler().scheduleJob(jobDetailBuilder.build(), triggerBuilder.build());
} catch (SchedulerException e) {
LOG.error("Could not schedule, aborting", e);
}
}
示例11: schedulerFactoryBean
import org.springframework.scheduling.quartz.SchedulerFactoryBean; //導入依賴的package包/類
@Bean
public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource) {
SchedulerFactoryBean factory = new SchedulerFactoryBean();
factory.setDataSource(dataSource);
//quartz參數
Properties prop = new Properties();
prop.put("org.quartz.scheduler.instanceName", "JxteleScheduler");
prop.put("org.quartz.scheduler.instanceId", "AUTO");
//線程池配置
prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
prop.put("org.quartz.threadPool.threadCount", "20");
prop.put("org.quartz.threadPool.threadPriority", "5");
//JobStore配置
prop.put("org.quartz.jobStore.class", "org.quartz.impl.jdbcjobstore.JobStoreTX");
//集群配置
prop.put("org.quartz.jobStore.isClustered", "true");
prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000");
prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1");
prop.put("org.quartz.jobStore.misfireThreshold", "12000");
prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_");
factory.setQuartzProperties(prop);
factory.setSchedulerName("RenrenScheduler");
//延時啟動
factory.setStartupDelay(30);
factory.setApplicationContextSchedulerContextKey("applicationContextKey");
//可選,QuartzScheduler 啟動時更新己存在的Job,這樣就不用每次修改targetObject後刪除qrtz_job_details表對應記錄了
factory.setOverwriteExistingJobs(true);
//設置自動啟動,默認為true
factory.setAutoStartup(true);
return factory;
}
示例12: 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;
}
示例13: before
import org.springframework.scheduling.quartz.SchedulerFactoryBean; //導入依賴的package包/類
@Before
public void before() throws Exception
{
// Create fresh scheduler
SchedulerFactoryBean sfb = new SchedulerFactoryBean();
sfb.setSchedulerFactoryClass(AlfrescoSchedulerFactory.class);
sfb.setAutoStartup(false);
sfb.afterPropertiesSet();
scheduler = sfb.getScheduler();
}
示例14: schedulerFactory
import org.springframework.scheduling.quartz.SchedulerFactoryBean; //導入依賴的package包/類
@Bean
public SchedulerFactoryBean schedulerFactory(ApplicationContext applicationContext) {
SchedulerFactoryBean factoryBean = new SchedulerFactoryBean();
AutowiringSpringBeanJobFactory jobFactory = new AutowiringSpringBeanJobFactory();
jobFactory.setApplicationContext(applicationContext);
factoryBean.setJobFactory(jobFactory);
factoryBean.setApplicationContextSchedulerContextKey("applicationContext");
return factoryBean;
}
示例15: 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;
}