The meaning of Quartz timing task configuration parameters

quartz. job-store-type

Specify the data storage method of the Quartz scheduler. The storage methods are as follows:
① RAM: use RAMJobStore to store task data, and the task data is stored in memory, which is suitable for a single-node environment.
② JDBC: Use JDBCJobStore to store task data, and task data is stored in a relational database, which is suitable for multi-node environments.
③ JNDI: Use JNDIJobStore to store task data, and task data is stored in JNDI, which is suitable for multi-node environments.
④ Quartz Scheduler API: Use the Quartz Scheduler API to store task data. The task data is stored in memory and is suitable for a single-node environment.
Among them, RAMJobStore and JDBCJobStore are the two most commonly used data storage methods. RAMJobStore is suitable for a single-node environment and is fast, simple and easy to use, but does not support cluster mode and persistent storage; JDBCJobStore is suitable for a multi-node environment and is reliable, stable and scalable, but it needs to configure the database and data source.


quartz. initialize-schema

Specifies whether the Quartz scheduler needs to initialize the data repository at startup. It should be noted that the initialize-schema property is only valid when using JDBCJobStore. If RAMJobStore or other data storage methods are used, this property does not need to be configured. The values ​​are as follows:
① true: Indicates that the Quartz scheduler needs to initialize the data repository at startup, that is, create the necessary tables and indexes.
② false: Indicates that the Quartz scheduler does not need to initialize the data repository at startup, that is, it will not create any tables and indexes.
③ always: Indicates that the Quartz scheduler will initialize the data repository every time it starts, that is, the necessary tables and indexes will be created every time it starts.
④ embedded: Indicates that the Quartz scheduler will use the embedded mode to initialize the data repository at startup, that is, create the necessary tables and indexes, and store the data in memory.
In practical applications, an appropriate initialize-schema property value can be selected according to actual requirements and the state of the data repository. If the data repository is brand new or the tables and indexes of the Quartz scheduler have not been created before, you can choose true or always; if the data repository already has tables and indexes of the Quartz scheduler, you can choose false to avoid repeated creation and coverage data. If you need to deploy the Quartz scheduler quickly and easily, and you don't need to store data persistently, you can choose the embedded mode.


quartz. auto-startup

It is used to specify whether the Quartz scheduler automatically starts the scheduled task when it starts. The values ​​are as follows:
① true: indicates that the Quartz scheduler automatically starts the scheduled task when it starts.
② false: Indicates that the Quartz scheduler does not automatically start the scheduled task at startup, and needs to manually call the start() method to start the scheduled task.
It should be noted that the auto-startup attribute only controls whether the Quartz scheduler automatically starts scheduled tasks at startup, and does not affect tasks that have been added to the scheduler. Even if the auto-startup attribute is false, tasks that have been added to the scheduler can still be executed normally.


quartz. startup-delay

It is used to specify how long the Quartz scheduler delays to start executing scheduled tasks after it starts. This parameter can be set as a time interval, such as 1s, 5m, 10h, etc. Using the startup-delay parameter can prevent the Quartz scheduler from executing scheduled tasks immediately when it starts, thereby reducing the load and resource consumption at startup. At the same time, you can also ensure that the Quartz scheduler and related resources are fully initialized and ready by setting an appropriate delay time to avoid exceptions and errors during startup.


quartz.overwrite-existing-jobs

It is used to specify whether the Quartz scheduler will overwrite an existing task with the same name when adding a task. The values ​​are as follows:
① true: indicates that the Quartz scheduler will overwrite an existing task with the same name when adding a task.
② false: Indicates that the Quartz scheduler will not overwrite existing tasks with the same name when adding tasks, and will throw an ObjectAlreadyExistsException.


quartz.properties.org.quartz.scheduler.instanceName

Used to specify the instance name of the Quartz scheduler. This attribute can be set to any string, which is used to distinguish different Quartz scheduler instances. Using the instanceName attribute can easily manage multiple Quartz scheduler instances, avoiding confusion and conflicts between different instances. For example, in a distributed system, a different instanceName can be set for the Quartz scheduler of each node to avoid task conflicts and repeated execution between nodes. It should be noted that the instanceName attribute must be unique and cannot be duplicated with the instanceName attribute of other Quartz scheduler instances. If repeated, it will cause the Quartz scheduler to fail to start or execute tasks.


quartz.properties.org.quartz.scheduler.instanceId

It is used to specify the instance ID of the Quartz scheduler, and the values ​​are as follows:
① Arbitrary parameter: This attribute can be set to any integer, which is used to distinguish different Quartz scheduler instances. Using the instanceId attribute can easily manage multiple Quartz scheduler instances, avoiding confusion and conflicts between different instances. For example, in a distributed system, a different instanceId can be set for the Quartz scheduler of each node to avoid task conflicts and repeated execution between nodes.
② AUTO: If the attribute is set to Auto, the Quartz scheduler will automatically assign a unique instanceId to each instance, and the Quartz scheduler will generate a unique instanceId based on the current time and random numbers.


quartz.properties.org.quartz.jobStore.class

It is used to specify the task storage method of the Quartz scheduler, and the values ​​are as follows:
1.org.quartz.simpl.RAMJobStore: Use memory to store task data, suitable for lightweight applications.
2.org.quartz.impl.jdbcjobstore.JobStoreTX: Use JDBC to store job data, support transaction management and cluster deployment.
3.org.quartz.impl.jdbcjobstore.JobStoreCMT: Use JDBC to store job data, support container management transactions and cluster deployment.
4.org.quartz.impl.jdbcjobstore.PostgreSQLDelegate: Use PostgreSQL database to store job data.
5.org.quartz.impl.jdbcjobstore.StdJDBCDelegate: Use a standard JDBC database to store task data.
6.org.quartz.impl.jdbcjobstore.oracle.OracleDelegate: Use the Oracle database to store task data.
7.org.quartz.impl.jdbcjobstore.weblogic.WebLogicDelegate: Use the WebLogic database to store task data.
8.org.quartz.impl.jdbcjobstore.mssql.MSSQLDelegate: Store task data using a Microsoft SQL Server database.
9.org.quartz.impl.jdbcjobstore.h2.H2Delegate: Use the H2 database to store job data.
10.org.quartz.impl.jdbcjobstore.SQLiteDelegate: Use SQLite database to store job data.
11.org.quartz.impl.jdbcjobstore.TerracottaJobStore: Use Terracotta to store task data, suitable for distributed applications.
12.org.springframework.scheduling.quartz.LocalDataSourceJobStore: Use the LocalDataSourceJobStore provided by Spring as a task storage method to support transaction management and cluster deployment.


quartz.properties.org.quartz.jobStore.tablePrefix

The database table prefix used to specify the task storage method of the Quartz scheduler


quartz.properties.org.quartz.jobStore.isClustered

Used to specify whether the Quartz scheduler is in cluster mode. This property can be set to true or false to specify whether the Quartz scheduler is in cluster mode.
If the isClustered property is set to true, it means that the Quartz scheduler is in cluster mode and can run on multiple nodes. In cluster mode, the Quartz scheduler uses database tables to store task data, and uses database locks to ensure the uniqueness and consistency of tasks.


quartz.properties.org.quartz.jobStore.misfireThreshold

Used to specify the misfire threshold for task triggers for the Quartz scheduler. This attribute can be set to an integer type value, which is used to specify the processing method of the task trigger of the Quartz scheduler when it misfires. The value of the misfireThreshold attribute indicates the misfire time allowed by the task trigger, in milliseconds. If the misfire time of the task trigger exceeds the value of the misfireThreshold attribute, the task trigger will be considered a misfire and will be processed according to the misfire processing policy.
The misfire processing strategy has the following methods:
① MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY: Ignore the misfire and continue to execute the next scheduling of the task trigger.
② MISFIRE_INSTRUCTION_SMART_POLICY: Intelligently handle misfire according to the type and status of task triggers. For example, if the task trigger is of type SimpleTrigger, the next scheduling time will be calculated according to the number of repetitions and interval time of the task trigger; if the task trigger is of type CronTrigger, the next scheduled time will be calculated according to the cron expression of the task trigger A schedule time.
③ MISFIRE_INSTRUCTION_FIRE_ONCE_NOW: Immediately execute the misfire task of the task trigger, and then continue to execute the next scheduling of the task trigger.
④ MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_EXISTING_REPEAT_COUNT: Immediately reschedule the task trigger, and use the number of repetitions of the task trigger to calculate the next scheduling time.
⑤ MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_REMAINING_REPEAT_COUNT: Immediately reschedule the task trigger, and use the remaining repetitions of the task trigger to calculate the next scheduling time.


quartz.properties.org.quartz.jobStore.clusterCheckinInterval

This attribute can be set to an integer value, which is used to specify the time interval for the Quartz scheduler to update its state to the database in cluster mode. It should be noted that the value of the clusterCheckinInterval attribute should be set according to the actual business scenario and cluster size. If the cluster size is large, you can appropriately increase the value of the clusterCheckinInterval attribute to reduce the pressure on the database; if the cluster size is small, you can appropriately reduce the value of the clusterCheckinInterval attribute to improve the scheduling accuracy.


quartz.properties.org.quartz.threadPool

Used to specify the thread pool configuration for the Quartz scheduler. This attribute can be set as a list of key-value pairs, which is used to specify parameters such as the thread pool size, thread priority, and thread name prefix of the Quartz scheduler.
Specific thread pool configuration parameters include:
① threadCount: The size of the thread pool, indicating the maximum number of tasks that the Quartz scheduler can execute simultaneously.
② threadPriority: thread priority, indicating the priority of the Quartz scheduler thread.
③ threadsInheritContextClassLoaderOfInitializingThread: Whether to inherit the context class loader of the initialization thread.
④ makeThreadsDaemons: Whether to set the Quartz scheduler thread as a daemon thread.
⑤ threadNamePrefix: thread name prefix, used to identify the name of the Quartz scheduler thread.
It should be noted that the size of the thread pool should be set according to actual business scenarios and system resources. If the system resources are sufficient, the size of the thread pool can be appropriately increased to increase the concurrency of tasks; if the system resources are limited, the size of the thread pool should be appropriately reduced to avoid waste of system resources.


Quartz sample configuration

 ## quartz定时任务,采用数据库方式
  quartz:
    job-store-type: jdbc
    initialize-schema: embedded
    #定时任务启动开关,true-开  false-关
    auto-startup: true
    #延迟1秒启动定时任务
    startup-delay: 1s
    #启动时更新己存在的Job
    overwrite-existing-jobs: true
    properties:
      org:
        quartz:
          scheduler:
            instanceName: MyScheduler
            instanceId: AUTO
          jobStore:
            class: org.springframework.scheduling.quartz.LocalDataSourceJobStore
            driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate
            tablePrefix: QRTZ_
            isClustered: true
            misfireThreshold: 12000
            clusterCheckinInterval: 15000
          threadPool:
            class: org.quartz.simpl.SimpleThreadPool
            threadCount: 10
            threadPriority: 5
            threadsInheritContextClassLoaderOfInitializingThread: true

The above is an example of configuring Quartz through a yaml file.


Guess you like

Origin blog.csdn.net/m0_37742400/article/details/130742051
Recommended