首页 > 解决方案 > 具有多实例 Spring Boot 应用程序的 Quartz 调度程序

问题描述

我只是想问几个关于 Quartz、PostgreSQL 和我的 spring boot 应用程序的问题。

我有一个名为“scheduleDemo”的 PostgreSQL 数据库。在那里,有时间表、作业和触发器的表格。

但是,我希望有两个不同的 spring boot 应用程序使用一些逻辑来执行不同类型的作业。

我的quartz.properties 是相同的,除了在两个应用程序中,但

org.quartz.scheduler.instanceName;那不一样。


org.quartz.scheduler.instanceName=springBootQuartzApp2
org.quartz.scheduler.instanceId=AUTO
org.quartz.threadPool.threadCount=5
org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
org.quartz.jobStore.useProperties=false
org.quartz.jobStore.misfireThreshold=60000
org.quartz.jobStore.tablePrefix=qrtz_
org.quartz.jobStore.isClustered=false
org.quartz.plugin.shutdownHook.class=org.quartz.plugins.management.ShutdownHookPlugin
org.quartz.plugin.shutdownHook.cleanShutdown=TRUE

org.quartz.jobStore.dataSource = abc
org.quartz.dataSource.abc.driver = org.postgresql.Driver
org.quartz.dataSource.abc.URL = jdbc:postgresql://localhost:5432/scheduledemo
org.quartz.dataSource.abc.user = postgres
org.quartz.dataSource.abc.password = postgres

我有这样的 SchedulerFactoryBean

    @Bean
    public SchedulerFactoryBean schedulerFactoryBean() throws IOException {

        SchedulerFactoryBean factory = new SchedulerFactoryBean();

        factory.setOverwriteExistingJobs(true);
        factory.setQuartzProperties(quartzProperties());
        AutowiringSpringBeanJobFactory jobFactory = new AutowiringSpringBeanJobFactory();
        jobFactory.setApplicationContext(applicationContext);
        factory.setJobFactory(jobFactory);

        return factory;

我有两个不同的类,它们实现了石英的 Job 接口,如 SimpleJob1.class 和 SimpleJob2.class。因为它们是不同的Scheduler,不应该互相感染吗?

当我从我的第一个应用程序提交 SimpleJob1.class 时,如果它错过了触发时间,我的第二个应用程序会引发错误。Beucase 在我的第二个 Spring Boot 应用程序中没有 SimpleJob1.class。

2020-05-06 18:35:15.356  INFO 31171 --- [_MisfireHandler] org.quartz.impl.jdbcjobstore.JobStoreTX  : Handling 3 trigger(s) that missed their scheduled fire-time.
2020-05-06 18:35:15.364 ERROR 31171 --- [_MisfireHandler] org.quartz.impl.jdbcjobstore.JobStoreTX  : MisfireHandler: Error handling misfires: Couldn't store trigger 'DEFAULT.alpcxsxsa2n' for 'SampleGroup.alpcxsxsa2n' job:Couldn't retrieve job because a required class was not found: com.javabypatel.demo.job.SimpleJob1

org.quartz.JobPersistenceException: Couldn't store trigger 'DEFAULT.alpcxsxsa2n' for 'SampleGroup.alpcxsxsa2n' job:Couldn't retrieve job because a required class was not found: com.javabypatel.demo.job.SimpleJob1

我的配置不好吗?或者这是一个不好的做法?

这个问题不好,但我没有用 Spring 配置 dataSource ?我应该使用 springJpa 提交数据源吗?

谢谢 !!

任何想法都会帮助我!

标签: springpostgresqlspring-bootquartz-schedulerquartz

解决方案


推荐阅读