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... ");
}
}