Quartz简单实现定时任务管理(SSM+Quartz)

首先你得有一个用Maven搭好的SSM框架,数据库用的Mysql,这里只有关于Quartz的部分。其实有大神总结的很好了,但做完后总有些地方不一样,所以写这篇作为笔记。这里先把大神的写的分享给大家:https://blog.csdn.net/u010648555/article/details/60767633

一、准备工作

1. 在maven的pom文件中添加Quartz的Jar坐标

<!-- quartz 定时器 -->
	<dependency>
	      <groupId>org.quartz-scheduler</groupId>
	      <artifactId>quartz</artifactId>
	      <version>2.2.1</version>
	</dependency>
	<dependency>
	      <groupId>org.quartz-scheduler</groupId>
	      <artifactId>quartz-jobs</artifactId>
	      <version>2.2.1</version>
	</dependency>

2. 在web.xml中添加quartz的监听器

<!-- 配置quartz监听器 -->
    <listener>
        <listener-class>
            org.quartz.ee.servlet.QuartzInitializerListener
        </listener-class>
    </listener>

3. 添加quartz.properties配置文件

# Configure Main Scheduler Properties
org.quartz.scheduler.instanceName: dufy_test
org.quartz.scheduler.instanceId = AUTO
org.quartz.scheduler.rmi.export: false
org.quartz.scheduler.rmi.proxy: false
org.quartz.scheduler.wrapJobExecutionInUserTransaction: false

# Configure ThreadPool
org.quartz.threadPool.class: org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount: 2
org.quartz.threadPool.threadPriority: 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread: true
org.quartz.jobStore.misfireThreshold: 60000

# Configure JobStore 持久化配置
#org.quartz.jobStore.class: org.quartz.simpl.RAMJobStore
org.quartz.jobStore.class:org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass:org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.useProperties:true

# 是否集群
org.quartz.jobStore.isClustered = false 

# 表前缀
org.quartz.jobStore.tablePrefix:qrtz_
#org.quartz.jobStore.dataSource:qzDS

# 下面是数据库的配置,交给Spring管理了
#org.quartz.dataSource.qzDS.driver:com.mysql.jdbc.Driver
#org.quartz.dataSource.qzDS.URL:jdbc:mysql://localhost:3306/quartz_test
#org.quartz.dataSource.qzDS.user:root
#org.quartz.dataSource.qzDS.password:123
#org.quartz.dataSource.qzDS.maxConnection:10

4. 添加Spring配置:applicationContext-quartz.xml

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring
  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值