Spring4+springmvc+quartz realization of multi-thread dynamic timing scheduling

Source: Internet
Author: User

Scheduler timing Scheduling system is required for most industry projects, the traditional spring-job mode, the personal feeling has been out, because there are a lot of problems, especially the timing of the addition of scheduling, modification, deletion, need to modify the XML, XML configuration in effect is nothing more than a hot deployment of gray-scale publishing scheme or directly stop, restart the server, completely can not do automatic startup, repair mode.

Reminder: The application can be deployed in a cluster, in the timing of scheduling configuration can use cluster mode or unilateral configuration application, today is the use of Spring4+scheduler to implement timing scheduling, gossip less, directly to the steps recorded:

1. In the project's Pom.xml file, introduce the Quartz jar package as follows:

Java code


650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/5712789-dc6f6382b411412d.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" height:auto;vertical-align:middle;border:0px; "alt=" 1240 "/>

Lt;dependency>

Org.quartz-scheduler

Quartz

1.8.5

Lt;/dependency>

2. Define the Quartz configuration file Spring-context-quartz.xml:

Java code


650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/5712789-573a3e068a945bd9.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" height:auto;vertical-align:middle;border:0px; "alt=" 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.xsd

Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd "

Default-lazy-init= "false" >

3. Introduction of the Spring-context-quartz.xml configuration file in the project's Web. xml file

Java code


650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/5712789-9f0d00f74ddb073a.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" height:auto;vertical-align:middle;border:0px; "alt=" 1240 "/>

4. Defining the Job Entity object

Java code


650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/5712789-e2681baa28a5139b.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" height:auto;vertical-align:middle;border:0px; "alt=" 1240 "/>

650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/5712789-c08d32077b321f41.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" height:auto;vertical-align:middle;border:0px; "alt=" 1240 "/>

650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/5712789-2d9bbcb73586fee4.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" height:auto;vertical-align:middle;border:0px; "alt=" 1240 "/>

5. Write the Jobservvice class for Quartz:

Java code


650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/5712789-6f95c7e34ee75668.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" height:auto;vertical-align:middle;border:0px; "alt=" 1240 "/>

650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/5712789-88ecdce9b79cd2c2.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" height:auto;vertical-align:middle;border:0px; "alt=" 1240 "/>

650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/5712789-f8631690ff831911.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" height:auto;vertical-align:middle;border:0px; "alt=" 1240 "/>

650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/5712789-316f39b1b751d494.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" height:auto;vertical-align:middle;border:0px; "alt=" 1240 "/>

650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/5712789-172ef26c2981b2bc.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" height:auto;vertical-align:middle;border:0px; "alt=" 1240 "/>

6. Writing related job Controller, DAO, Dao.xml I will not write on this side, in fact, the data to delete and change the operation

7. Start the project to verify that the quartz is successful:

Project launches a console:


650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/5712789-488b2450f1a25c8e.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" height:auto;vertical-align:middle;border:0px; "alt=" 1240 "/>


650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/5712789-cafbc06721d018d0.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" height:auto;vertical-align:middle;border:0px; "alt=" 1240 "/>


650) this.width=650; "Src=" Http://upload-images.jianshu.io/upload_images/5712789-abd1362d89e46810.png?imageMogr2 /auto-orient/strip%7cimageview2/2/w/1240 "style=" height:auto;vertical-align:middle;border:0px; "alt=" 1240 "/>

Willing to understand the framework of technology or source of friends directly seeking exchange sharing technology: 2042849237

Some of the distributed solutions, the friends who are willing to know can find our team to discuss

More detailed source code reference: Http://minglisoft.cn/technology


Spring4+springmvc+quartz realization of multi-thread dynamic timing scheduling

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.