Spring with Java Quartz Configuration instance code

Source: Internet
Author: User

Original: Spring with Java Quartz Configuration instance code

Source code: Http://www.zuidaima.com/share/1787232442715136.htm

A variety of enterprise applications will almost meet the needs of task scheduling, take the forum: every half an hour to generate the essence of the article's RSS file, every morning to statistics forum users points rankings, every 30 minutes to perform lock user unlock task. For a typical MIS system, in the early month of 1th monthly statistics of each department's business data generated monthly report, every half an hour to check whether the user has a fast-maturing business to be processed ..., such examples abound, numerous.

Quartz in the framework of open source task scheduling, it provides a powerful task scheduling mechanism, it is commendable that it also maintain the simplicity of use. Quartz allows developers the flexibility to define scheduling schedules for triggers and to associate mappings of triggers and tasks.
Spring provides a convenient Factorybean class for creating quartz scheduler, trigger, and jobdetail so that the benefits of injection can be enjoyed in the spring container. In addition, Spring provides some handy tool classes that directly package the beans in spring into legitimate tasks. Spring further reduces the difficulty of using quartz and can use quartz in a more spring-style manner. In summary, it provides support in two ways:
1) Provide a more bean-style extension class for the important component classes of quartz;
2) provides the Beanfactory class for creating scheduler, which facilitates the creation of corresponding component objects in the spring environment and the action of starting and stopping with the spring container life cycle.
Configuration file:

<?xml version= "1.0" encoding= "UTF-8"?> <! DOCTYPE beans Public "-//spring//dtd bean//en" "Http://www.springframework.org/dtd/spring-beans.dtd" > &LT;BEANS&G  T <!--the work class to invoke--<bean id= "quartzjob" class= "test. Task ></bean> <!--define methods for calling objects and calling objects--<bean id= "Jobtask" class= "Org.springframework.scheduling.qu Artz. Methodinvokingjobdetailfactorybean "> <!--called Class-<property name=" TargetObject "> <ref bean=" Quar Tzjob "/> </property> <!--calling methods in class--<property Name=" Targetmethod "> <value> work </ Value> </property> </bean> <!--define trigger time-<bean id= "Dotime" class= "Org.springframework.sc Heduling.quartz.CronTriggerBean "> <property name=" jobdetail "> <ref bean=" jobtask "/> </property&  Gt  <!--cron expression---<property name= "cronexpression" > <value>,,,,,,,,, * * * * *?</value> </propertY> </bean> <!--General Management class if you lazy-init= ' false ' then the container starts executing the scheduler--<bean id= "Startquertz" Lazy-init = "false" autowire= "no" class= "Org.springframework.scheduling.quartz.SchedulerFactoryBean" > <property name= " Triggers "> <list> <ref bean=" Dotime "/> </list> </property> </bean> </beans&  Gt

Work class to dispatch:

public class task{public void work () {System.out.println ("Quartz Task Scheduler! " ); }}

Main test file:

public class Quartztest {public static void main (string[] args) {System.out.println ("Test start."); ApplicationContext context= New Classpathxmlapplicationcontext ("Applicationcontext.xml"); If you set the Startquertz Bean's lazy-init to false in the configuration file, you do not instantiate  System.out.print ("Test End: \ n ");}}


Note: Items that need to be loaded need to be added Spring.jar quartz-all-1.6.0.jar log4j-1.2.14.jar commons-collections.jar Jta.jar COMMONS-LOGGING.J Ar these several bags

Spring with Java Quartz Configuration instance code

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.