Spring4+Springmvc+quartz实现多线程动态定时调度

来源:互联网 发布:金瑞期货软件 编辑:程序博客网 时间:2024/06/07 22:46

scheduler定时调度系统是大多行业项目都需要的,传统的spring-job模式,个人感觉已经out了,因为存在很多的问题,特别是定时调度的追加、修改、删除等,需要修改xml,xml的配置生效无非是热部署灰度发布方案或者直接停止、重启服务器,完全不能做到自动启动、修复方式。

提醒:可以对应用进行集群部署,在对定时调度配置时可以使用集群方式或者单边配置应用方式,今天讲解的是使用spring4+scheduler实现定时调度,闲话少说,直接把步骤记录下来:

1. 在项目的pom.xml文件中引入quartz的jar包,如下:

Java代码



lt;dependency>

org.quartz-scheduler

quartz

1.8.5

lt;/dependency>

2. 定义quartz的配置文件spring-context-quartz.xml:

Java代码



xmlns:context="http://www.springframework.org/schema/context"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"

default-lazy-init="false">

3.  在项目的web.xml文件中引入spring-context-quartz.xml配置文件

Java代码



4. 定义job实体对象

Java代码





5. 编写quartz的jobServvice类:

Java代码







6. 编写相关job的Controller、dao、dao.xml我这边就不写了,其实就是对数据的增删改查操作

7. 启动项目验证quartz是否成功:

项目启动个控制台:







愿意了解框架技术或者源码的朋友直接求求交流分享技术:2042849237

分布式的一些解决方案,有愿意了解的朋友可以找我们团队探讨

更多详细源码参考来源:http://minglisoft.cn/technology

阅读全文
5 0