Search in sources :

Example 11 with SchedulerFactoryBean

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();
        }
    }
}
Also used : Trigger(org.quartz.Trigger) CronTriggerFactoryBean(org.springframework.scheduling.quartz.CronTriggerFactoryBean) SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean) ParseException(java.text.ParseException) Job(com.weicoder.frame.quartz.Job) Map(java.util.Map) MethodInvokingJobDetailFactoryBean(org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean) ParseException(java.text.ParseException) PostConstruct(javax.annotation.PostConstruct)

Example 12 with SchedulerFactoryBean

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;
}
Also used : Trigger(org.quartz.Trigger) SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean) Properties(java.util.Properties) Bean(org.springframework.context.annotation.Bean) SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean)

Example 13 with SchedulerFactoryBean

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;
}
Also used : SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean) Properties(java.util.Properties) FactoryBean(org.springframework.beans.factory.FactoryBean) SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean) LocalSessionFactoryBean(org.springframework.orm.hibernate5.LocalSessionFactoryBean) SqlSessionFactoryBean(org.mybatis.spring.SqlSessionFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 14 with SchedulerFactoryBean

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;
}
Also used : SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean) Bean(org.springframework.context.annotation.Bean) SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean)

Example 15 with SchedulerFactoryBean

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;
}
Also used : SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean) IOException(java.io.IOException) ClassPathResource(org.springframework.core.io.ClassPathResource) Bean(org.springframework.context.annotation.Bean) SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean)

Aggregations

SchedulerFactoryBean (org.springframework.scheduling.quartz.SchedulerFactoryBean)28 Bean (org.springframework.context.annotation.Bean)20 PropertiesFactoryBean (org.springframework.beans.factory.config.PropertiesFactoryBean)7 ClassPathResource (org.springframework.core.io.ClassPathResource)6 IOException (java.io.IOException)5 Properties (java.util.Properties)5 Test (org.junit.jupiter.api.Test)3 JobDetail (org.quartz.JobDetail)3 Trigger (org.quartz.Trigger)3 CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)2 Map (java.util.Map)2 PostConstruct (javax.annotation.PostConstruct)2 SchedulerException (org.quartz.SchedulerException)2 ServerSettings (com.radensolutions.reporting.service.ServerSettings)1 Job (com.weicoder.frame.quartz.Job)1 SchedulerManager (eu.bcvsolutions.idm.core.scheduler.api.service.SchedulerManager)1 DefaultSchedulerManager (eu.bcvsolutions.idm.core.scheduler.service.impl.DefaultSchedulerManager)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1