Java Spring's quartz configuration usage tutorial

Source: Internet
Author: User
Tags class definition current time

Usage Environment: ECLIPSE+MAVEN+SPRING+QUARTZ1
Use purpose: Perform the timer to complete the scan operation.
Puzzle point: Using the QUARTZ2 version will appear inexplicable errors, similar to the interface and class definition of the difference. Look at the document and don't get it straight.

Use steps:

1. Configure the MAVEN profile (configured with the QUARTZ1 version), pom.xml add the code:

The code is as follows Copy Code

<!--add Quartz frame-->
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>1.8.5</version>
</dependency>

<!--components Optional-->
<!--start-->
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>

<dependency>
<groupId>commons-digester</groupId>
<artifactId>commons-digester</artifactId>
<version>1.8</version>
</dependency>

<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.8.3</version>
</dependency>
<!--end-->

2. Configure the Spring profile Spring.xml file to load the Quartz. configuration file with the following code:
<!--: Using Methodinvokingjobdetailfactorybean, the task class can specify the calling method by Targetmethod without implementing the job interface-->
<!--define methods in the target bean and bean-->
<bean id= "Springqtzjob"
class= "Com.founder.centerbusiness.controller.basicMgr.RuleMgrController"/>
<bean id= "Springqtzjobmethod"
class= "Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" >
<property name= "TargetObject" >
<ref bean= "Springqtzjob"/>
</property>
<property name= "Targetmethod" > <!--the name of the method to be executed-->
<value>execute</value>
</property>
</bean>

<!--======================== scheduling trigger ========================-->
<bean id= "Crontriggerbean" class= "Org.springframework.scheduling.quartz.CronTriggerBean" >
<property name= "Jobdetail" ref= "Springqtzjobmethod" ></property>
<!--0/1 * * * *? : Perform a--> scan every second
<property name= "cronexpression" value= "0/1 * * * *?" ></property>
</bean>

<!--======================== Dispatch factory ========================-->
<bean id= "Springjobschedulerfactorybean"
class= "Org.springframework.scheduling.quartz.SchedulerFactoryBean" >
<property name= "Triggers" >
<list>
<ref bean= "Crontriggerbean"/>
</list>
</property>
</bean>

which
<!--0/2 * * * *? : Perform a--> scan every second
<property name= "cronexpression" value= "0/2 * * * *?" ></property>
That's a scan every 1 seconds.
<!--0/8 * * * *? : Perform a--> scan every 8 seconds
<property name= "cronexpression" value= "0/8 * * * *?" ></property>
That's a scan every 8 seconds.
What is the meaning of the specific *, to ask the degree of the Empress.

Id= "Springqtzjob" represents the local file path in which the action is performed.
3. Local execution Java file code is as follows:
/**
* Execution Timer
*/
protected void execute () {
String currenttime = Dateutils.getdatetime ();
System.out.println ("Current Time--->" + currenttime);
}

The code screenshot is as follows:

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.