quartz 进行时间调度(配置式)

本文详细介绍如何使用Quartz进行定时任务的配置,包括通过Java代码启动Quartz调度器、配置quartz.properties文件以及创建quartz-jobs.xml来定义具体的定时任务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

   
启动Quartz:

StdSchedulerFactory sf = new StdSchedulerFactory();
sf.initialize("quartz.properties");
Scheduler scheduler = sf.getScheduler();
scheduler.start();


quartz.properties 配置:

# Default Properties file for use by StdSchedulerFactory
# to create a Quartz Scheduler Instance, if a different
# properties file is not explicitly specified.
#
org.quartz.scheduler.instanceName: DefaultQuartzScheduler
org.quartz.scheduler.rmi.export: false
org.quartz.scheduler.rmi.proxy: false
org.quartz.scheduler.wrapJobExecutionInUserTransaction: false

#
org.quartz.threadPool.class: org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount: 25
org.quartz.threadPool.threadPriority: 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread: true

#
org.quartz.jobStore.misfireThreshold: 60000
org.quartz.jobStore.class: org.quartz.simpl.RAMJobStore


#
org.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin
org.quartz.plugin.triggHistory.class = org.quartz.plugins.history.LoggingJobHistoryPlugin
org.quartz.plugin.jobInitializer.fileNames = quartz-jobs.xml
org.quartz.plugin.jobInitializer.failOnFileNotFound = true
org.quartz.plugin.jobInitializer.scanInterval = 1000000000
org.quartz.plugin.jobInitializer.wrapInUserTransaction = false


quartz-jobs.xml 文件配置:

<?xml version="1.0" encoding="UTF-8"?>
<job-scheduling-data xmlns="http://www.quartz-scheduler.org/xml/JobSchedulingData"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.quartz-scheduler.org/xml/JobSchedulingData http://www.quartz-scheduler.org/xml/job_scheduling_data_1_8.xsd"
version="1.8">
<schedule>

<job>
<name>SendEmail(自定义)</name>
<group>QUARTZ_DEFAULT_JOB_GROUP(自定义)</</group>
<description>The job description(自定义)</</description>
<job-class>(你需要执行的class)</class>
</job>
<trigger>
<cron>
<name>SendEmailTrigger(自定义)</name>
<group>QUARTZ_DEFAULT_TRIGGER_GROUP(自定义)</</group>
<job-name>SendEmail(自定义)</job-name>
<job-group>QUARTZ_DEFAULT_JOB_GROUP(自定义)</job-group>
<cron-expression>0 0 23 * * ?(调度时间设置)</cron-expression>
</cron>
</trigger>
</schedule>
</job-scheduling-data>


[b]另附几篇博客地址:[/b][url]http://kdisk-sina-com.iteye.com/category/74089[/url]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值