First download the quartz-1.6.0.jar shelf package to the lib directory
2. Write your own timer Business Method
Package com. lbnet. lzx. timing;
Import org. quartz. JobExecutionContext;
Import org. quartz. JobExecutionException;
Import org. springframework. beans. factory. BeanFactory;
Import org. springframework. context. support. ClassPathXmlApplicationContext;
Import org. springframework. scheduling. quartz. QuartzJobBean;
Import com. lbnet. lzx. service. IOrderService;
Public class OrderNoRefact extends QuartzJobBean {
Private static BeanFactory factory = new ClassPathXmlApplicationContext ("applicationContext-*. xml ");
@ Override
Protected void executeInternal (JobExecutionContext arg0)
Throws JobExecutionException {
// TODO Auto-generated method stub
IOrderService orderdao = (IOrderService) factory. getBean ("OrderServiceImpl ");
System. out. println ("Order timed out! ");
Orderdao. updateOrderTimeOver ();
}
}
3. Configure in the spring File
Configure scheduled tasks
<Bean id = "SchedulerTask3" class = "org. springframework. scheduling. quartz. JobDetailBean">
<Property name = "jobClass">
<Value> com. lbnet. lzx. timing. OrderNoRefact </value>
</Property>
</Bean>
Configure the scheduled time
<Bean id = "SchedulerTaskTrigger3" class = "org. springframework. scheduling. quartz. CronTriggerBean">
<Property name = "jobDetail" ref = "SchedulerTask3"/>
<Property name = "cronExpression">
<Value> 0 0/30 0/1 **? </Value>
</Property>
</Bean>
Enable scheduled task
<Bean class = "org. springframework. scheduling. quartz. SchedulerFactoryBean">
<Property name = "triggers">
<List>
<Ref bean = "SchedulerTaskTrigger3"/>
</List>
</Property>
</Bean>
4. Meanings of some scheduled Parameters
0 0/30 0/1 **? Indicates running every 30 minutes every day.
0 0/3 0/1 **? Indicates running every 3 minutes every day.
0 11 23 **? Indicates that the task runs once every night.
5. If an exception is reported during restart
Org. apache. commons. collections. SetUtils. orderedSet (Ljava/util/Set;) Ljava/util/Set;
Please remove the commons-collections-2.1.1.jar, checkstytle-all.jar, and then add the commons-collections.jar package on OK
========================================================== ======
The running time of Spring scheduling tasks can be configured through the TriggerBean attribute. Generally, SimpleTriggerBean is used instead of SimpleTriggerBean.
CronTriggerBean. The configurations of the two triggerbeans are described as follows:
1) SimpleTriggerBean Configuration:
<Bean id = "trigger. jobdetail"
Class = "org. springframework. scheduling. quartz. SimpleTriggerBean">
<Property name = "jobDetail">
<Ref bean = "factory"/>
</Property>
<Property name = "startDelay">
<! -- 10 seconds is measured in milliseconds. The default value is 10 seconds. -->
<Value> 10000 </value>
</Property>
<Property name = "repeatInterval">
<! -- Repeat every 600 the unit of seconds is millisecond. The default value is 10 minutes. -->
<Value> 60000 </value>
</Property>
</Bean>
Bean configuration of the scheduled task
<Bean id = "factory"
Class = "org. springframework. scheduling. quartz. MethodInvokingJobDetailFactoryBean">
<Property name = "targetObject">
<Ref bean = "dailyjob. processor"/>
</Property>
<Property name = "targetMethod">
<Value> process </value>
</Property>
</Bean>
2) CronTriggerBean Configuration:
Set to execute every minute. SimpleTriggerBean can only specify the frequency of execution, but cannot specify the specific time of execution.
For example, if you want to execute a specific job at every night, SimpleTriggerBean cannot meet the requirement.
A bean: CronTriggerBean.
<Bean id = "Detail"
Class = "org. springframework. scheduling. quartz. MethodInvokingJobDetailFactoryBean">
<Property name = "targetObject"> <ref bean = "mainServer"/> </property>
<Property name = "targetMethod"> <value> excute </value> </property>
</Bean>
Set a trigger
<Bean id = "HRTrigger" class = "org. springframework. scheduling. quartz. CronTriggerBean">
<Property name = "jobDetail"> <ref bean = "Detail"/> </property>
<Property name = "cronExpression"> <value> 0/10 ****? </Value> </property>
</Bean>
<! -- Start trigger -->
<Bean class = "org. springframework. scheduling. quartz. SchedulerFactoryBean">
<Property name = "triggers">
<List>
<! -- Add a trigger -->
<Ref local = "HRTrigger"/>
</List>
</Property>
</Bean>