本文整理汇总了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;
}