Spring quartz Integration

Source: Internet
Author: User

1. scheduled execution class

[Java]
Package thb. quartz;
 
Public class QuartzJob {

/**
* Scheduled execution Method
*/
Public void work (){
System. out. println (System. currentTimeMillis () + ">>> run a scheduled task... ");
}
 
}

2. quartz configuration file
[Java]
<? Xml version = "1.0" encoding = "UTF-8"?>
<Beans xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xmlns: util = "http://www.springframework.org/schema/util"
Xsi: schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd"
Default-lazy-init = "true">

<! -- The class for calling the scheduled task -->
<Bean id = "quartzJob" class = "thb. quartz. QuartzJob"> </bean>

<! -- Define the methods (triggers) for calling objects and calling objects -->
<Bean id = "jobTask" class = "org. springframework. scheduling. quartz. MethodInvokingJobDetailFactoryBean">
<! -- Called class -->
<Property name = "targetObject">
<Ref bean = "quartzJob"/>
</Property>
<! -- Call Method -->
<Property name = "targetMethod">
<Value> work </value>
</Property>
</Bean>

<! -- Define the trigger event (Scheduler) -->
<Bean id = "doTime" class = "org. springframework. scheduling. quartz. CronTriggerBean">
<Property name = "jobDetail" ref = "jobTask"> </property>
<! -- Start at, every 1 minute -->
<Property name = "cronExpression" value = "0*10 **? "> </Property>
</Bean>

<Bean id = "startQuartz" lazy-init = "false" autowire = "no" class = "org. springframework. scheduling. quartz. SchedulerFactoryBean">
<Property name = "triggers">
<List>
<Ref bean = "doTime"/>
</List>
</Property>
</Bean>
</Beans>

3. Test code
[Java] www.2cto.com
Package thb. quartz;
 
Import org. springframework. context. ApplicationContext;
Import org. springframework. context. support. FileSystemXmlApplicationContext;
 
Public class QuartzTest {
 
/**
* Scheduled task test
*/
Public static void main (String [] args ){
ApplicationContext ctx = new FileSystemXmlApplicationContext ("/resource/spring/quartz. xml ");
System. out. println ("scheduled task starts to run... ");
}
 
}

 

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.