当前位置: 首页 > 知识库问答 >
问题:

Spring Boot Quartz调度程序配置

谭梓
2023-03-14
@SpringBootApplication
public class MyApp{
    public static void main(String[] args) {
        SpringApplication.run(MyApp.class, args);
    }

    ...

    @Bean
    public Scheduler scheduler(SomeCustomConfig cfg, RestTemplate restTemplate) throws SchedulerException {
        //StdSchedulerFactory schedulerFactory = new StdSchedulerFactory();
        //schedulerFactory.initialize("quartz.properties");
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
        scheduler.getContext().put("restTemplate", restTemplate);
        scheduler.getContext().put("cfg", cfg);
        return scheduler;
    }

}

相关application.yml:

spring:
    application.name: myApp
    quartz:
        properties:
            org:
                quartz:
                    scheduler:
                        instanceId: AUTO
                    threadPool:
                        threadCount: 5
                    plugin:
                        shutdownhook:
                            class: org.quartz.plugins.management.ShutdownHookPlugin
                            cleanShutdown: TRUE
                    jobStore:
                        class: org.quartz.impl.jdbcjobstore.JobStoreTX
                        driverDelegateClass: org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
                        tablePrefix: my_schema.
                        isClustered: true
                        dataSource: myDataSource
                    dataSource:
                        myDataSource:
                            driver: org.postgresql.Driver
                            URL: jdbc:postgresql://localhost/myDataSource
                            user: removed
                            password: removed
org.quartz.scheduler.instanceId = AUTO
org.quartz.plugin.shutdownhook.class = org.quartz.plugins.management.ShutdownHookPlugin
org.quartz.plugin.shutdownhook.cleanShutdown = TRUE
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.tablePrefix = my_schema.
org.quartz.jobStore.isClustered = true
org.quartz.jobStore.dataSource = myDataSource
org.quartz.dataSource.myDataSource.driver = org.postgresql.Driver
org.quartz.dataSource.myDataSource.URL = jdbc:postgresql://localhost/myDataSource
org.quartz.dataSource.myDataSource.user = removed
org.quartz.dataSource.myDataSource.password = removed

我觉得我错过了什么?

共有1个答案

元景天
2023-03-14

而不是

spring:
  quartz:
    properties:
      org:
        quartz:
          jobStore:
            isClustered: true

使用此布局:

spring:
  quartz:
    properties:
      org.quartz.jobStore:
        isClustered: true
      org.quartz.scheduler:
        instanceId: AUTO

对于后一种布局,我得到:

2019-09-06 13:45:19.919  INFO PID --- [           main] o.q.c.QuartzScheduler                    : {} Scheduler meta-data: Quartz Scheduler (v2.3.0) 'quartzScheduler' with instanceId '0157799997'
  Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
  NOT STARTED.
  Currently in standby mode.
  Number of jobs executed: 0
  Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.
  Using job-store 'org.springframework.scheduling.quartz.LocalDataSourceJobStore' - which supports persistence. and is clustered.
 类似资料:
  • 问题内容: 我正在尝试为我的项目需求实现简单的调度程序,我的项目正在使用。到目前为止,我浏览了Adobe网站并尝试实现所提供的示例,但是没有一个示例可以更新我的文件。 因此,根据这个,它应该工作 依赖 我是否需要进行其他任何更改才能使调度程序正常工作?请建议缺少的内容。 问题答案: 以下解决方案按要求工作,这里处理了三种情况 with :每分钟执行一次作业 with :每3分钟执行一次作业 wit

  • 我正在做一个项目,我们计划使用WLP (WebSphere liberty)代替传统的WAS。 代码使用 WAS 调度程序来调度活动。 liberty 是否也具有与 WAS 中存在的相同级别的调度程序支持/功能? 如何将调度程序任务从webphere迁移到自由?

  • 这些是什么,我们应该如何配置它们,以查看它们如何影响应用程序性能? 谢谢!

  • 主要内容:1. 串行调度,2. 非串行调度从一个事务到另一个事务的一系列操作称为调度。 它用于保存每个单独事务中的操作顺序。 1. 串行调度 串行调度是一种调度,其中一个事务在开始另一个事务之前完全执行。 在串行调度中,当第一个事务完成其循环时,则执行下一个事务。 例如: 假设有两个事务和有一些操作。 如果它没有交错操作,那么有以下两种可能的结果: 执行的所有操作,然后执行的所有操作。 在给定的(b)图中,调度A显示了序列调度,其中之后跟

  • 我使用RxJava2 Android网络的网络调用。我面临的问题是,当我试图通过命中API时,有时它不会给出任何响应,而当我试图通过命中API时,它总是给出回应 和

  • 问题内容: 在Akka文档中指出,如果未配置调度程序,则将使用默认调度程序。默认调度程序的属性是什么,即并行度最小值,并行度因子,并行度最大值等? 问题答案: 默认情况下,提供的调度程序是带有的调度程序,并且默认的并行度值为: 最小并行度: 8 并行因子: 3.0 最大并行度: 64 您可以在文档中看到所有这些信息。 有一个节名为: 参考配置清单 这是配置文件的相关部分(我只删除了注释):