use of org.springframework.scheduling.quartz.SchedulerFactoryBean in project weicoder by wdcode.
the class QuartzStarter method init.
/**
* 初始化
*/
@PostConstruct
protected void init() {
// 定时任务
if (QuartzParams.SPRING) {
// 声明定时对象
List<Trigger> triggers = Lists.newList();
// 循环设置
for (Job job : context.getBeans(Job.class).values()) {
// 设置任务
for (Map.Entry<String, String> e : job.getTriggers().entrySet()) {
// 声明方法执行bean
MethodInvokingJobDetailFactoryBean method = new MethodInvokingJobDetailFactoryBean();
// 设置任务对象
method.setTargetObject(job);
// 设置不可以并发
method.setConcurrent(false);
// // 设置执行方法
method.setTargetMethod(e.getKey());
// 设置group
method.setGroup(job.getClass().getSimpleName());
// 设置beanName
method.setBeanName(e.getKey());
try {
// 执行初始化
method.afterPropertiesSet();
} catch (Exception ex) {
}
// 执行执行时间
for (String trigger : e.getValue().split(StringConstants.COMMA)) {
// 执行时间对象
CronTriggerFactoryBean cron = new CronTriggerFactoryBean();
// 设置group
cron.setGroup(method.getTargetObject().getClass().getSimpleName());
// 设置beanName
cron.setBeanName(method.getTargetMethod());
// 设置任务对象
cron.setJobDetail(method.getObject());
// 设置时间
cron.setCronExpression(trigger);
// 执行初始化
try {
cron.afterPropertiesSet();
} catch (ParseException ex) {
Logs.error(ex);
}
// 添加到定时列表中
triggers.add(cron.getObject());
}
}
}
// 定时任务不为空
if (!EmptyUtil.isEmpty(triggers)) {
// 声明执行定时方法工厂
SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
// 设置执行时间
scheduler.setTriggers(Lists.toArray(triggers));
// scheduler.init();
try {
// 执行初始化
scheduler.afterPropertiesSet();
} catch (Exception e) {
}
// 执行
scheduler.start();
}
}
}
use of org.springframework.scheduling.quartz.SchedulerFactoryBean in project simba-os by cegeka.
the class JobSchedulerConfiguration method schedulerFactory.
@Bean(destroyMethod = "destroy")
public SchedulerFactoryBean schedulerFactory() {
Properties quartzProperties = new Properties();
quartzProperties.put("org.quartz.threadPool.threadCount", "2");
quartzProperties.put("org.quartz.jobStore.driverDelegateClass", quartzJobstoreDelegate);
Trigger[] triggers = new Trigger[] { verifyAuditLogIntegrityTrigger, cleanUpAuditLogTrigger, purgeExpiredLoginMappingsTrigger, purgeExpiredSessionsTrigger, purgeExpiredTokensTrigger, markUsersForPasswordChangeTrigger };
SchedulerFactoryBean bean = new SchedulerFactoryBean();
bean.setDataSource(dataSource);
bean.setWaitForJobsToCompleteOnShutdown(false);
bean.setApplicationContextSchedulerContextKey("applicationContext");
bean.setQuartzProperties(quartzProperties);
bean.setTriggers(triggers);
return bean;
}
use of org.springframework.scheduling.quartz.SchedulerFactoryBean in project PublicCMS-preview by sanluan.
the class ApplicationConfig method scheduler.
/**
* 任务计划工厂
*
* @return task scheduler factory
*/
@Bean
public SchedulerFactoryBean scheduler() {
SchedulerFactoryBean bean = new SchedulerFactoryBean();
Properties properties = new Properties();
properties.setProperty(SchedulerFactoryBean.PROP_THREAD_COUNT, env.getProperty("cms.task.threadCount"));
bean.setQuartzProperties(properties);
return bean;
}
use of org.springframework.scheduling.quartz.SchedulerFactoryBean in project molgenis by molgenis.
the class SchedulerConfig method schedulerFactoryBean.
@Bean
public SchedulerFactoryBean schedulerFactoryBean() {
SchedulerFactoryBean quartzScheduler = new SchedulerFactoryBean();
AutowiringSpringBeanJobFactory jobFactory = new AutowiringSpringBeanJobFactory();
jobFactory.setApplicationContext(applicationContext);
quartzScheduler.setJobFactory(jobFactory);
return quartzScheduler;
}
use of org.springframework.scheduling.quartz.SchedulerFactoryBean in project moon by gentoo111.
the class JobConfig method quartzScheduler.
@Bean("adminQuartzScheduler")
public SchedulerFactoryBean quartzScheduler(DataSource dataSource) {
SchedulerFactoryBean quartzScheduler = new SchedulerFactoryBean();
try {
quartzScheduler.setQuartzProperties(PropertiesLoaderUtils.loadProperties(new ClassPathResource("quartz.properties")));
} catch (IOException e) {
e.printStackTrace();
}
quartzScheduler.setDataSource(dataSource);
quartzScheduler.setOverwriteExistingJobs(true);
quartzScheduler.setApplicationContextSchedulerContextKey(KEY);
quartzScheduler.setStartupDelay(10);
return quartzScheduler;
}
Aggregations