Spring4+Springmvc+quartz实现多线程动态定时调度
scheduler定时调度系统是大多行业项目都需要的,传统的spring-job模式,个人感觉已经out了,因为存在很多的问题,特别是定时调度的追加、修改、删除等,需要修改xml,xml的配置生效无非是热部署灰度发布方案或者直接停止、重启服务器,完全不能做到自动启动、修复方式。提醒:可以对应用进行集群部署,在对定时调度配置时可以使用集群方式或者单边配置应用方式,今天讲解的是使用spring4+scheduler实现定时调度,闲话少说,直接把步骤记录下来:1. 在项目的pom.xml文件中引入quartz的jar包,如下:Java代码http://upload-images.jianshu.io/upload_images/5712789-dc6f6382b411412d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240
lt;dependency>org.quartz-schedulerquartz1.8.5lt;/dependency>2. 定义quartz的配置文件spring-context-quartz.xml:Java代码
http://upload-images.jianshu.io/upload_images/5712789-573a3e068a945bd9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240
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.xsdhttp://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代码
http://upload-images.jianshu.io/upload_images/5712789-9f0d00f74ddb073a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240
4. 定义job实体对象Java代码
http://upload-images.jianshu.io/upload_images/5712789-e2681baa28a5139b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240
http://upload-images.jianshu.io/upload_images/5712789-c08d32077b321f41.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240
http://upload-images.jianshu.io/upload_images/5712789-2d9bbcb73586fee4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240
5. 编写quartz的jobServvice类:Java代码
http://upload-images.jianshu.io/upload_images/5712789-6f95c7e34ee75668.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240
http://upload-images.jianshu.io/upload_images/5712789-88ecdce9b79cd2c2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240
http://upload-images.jianshu.io/upload_images/5712789-f8631690ff831911.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240
http://upload-images.jianshu.io/upload_images/5712789-316f39b1b751d494.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240
http://upload-images.jianshu.io/upload_images/5712789-172ef26c2981b2bc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240
6. 编写相关job的Controller、dao、dao.xml我这边就不写了,其实就是对数据的增删改查操作7. 启动项目验证quartz是否成功:项目启动个控制台:
http://upload-images.jianshu.io/upload_images/5712789-488b2450f1a25c8e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240
http://upload-images.jianshu.io/upload_images/5712789-cafbc06721d018d0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240
http://upload-images.jianshu.io/upload_images/5712789-abd1362d89e46810.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240
愿意了解框架技术或者源码的朋友直接求求交流分享技术:2042849237分布式的一些解决方案,有愿意了解的朋友可以找我们团队探讨更多详细源码参考来源:http://minglisoft.cn/technology
页:
[1]