Spring regular Scheduling

Source: Internet
Author: User

A report computing server is used in the project. When the project runs, the related computing methods are started.

I thought about it. spring is a java web project and it manages everything. Check whether the scheduled scheduling function is available.

Spring provides two triggers: CronTriggerBean and SimpleTriggerBean.

So lazy. Let's make a short speech.

Environment: spring + ibatis. First configure the spring configuration file. Write the service layer (the specific calculation method is written here ).

 

1. CronTriggerBean

[Html]
<! -- Define job -->
<Bean name = "mathsJob1"
Class = "org. springframework. scheduling. quartz. MethodInvokingJobDetailFactoryBean">
<! -- Injected service layer -->
<Property name = "targetObject" ref = "mathsService"/>
<! -- Call Method --> www.2cto.com
<Property name = "targetMethod" value = "aotoMathsMethod1"/>
<! -- If concurrent is true, a QuartzJob can be executed concurrently. Otherwise, the job is executed sequentially. -->
<Property name = "concurrent" value = "false"/>
</Bean>
 
<! -- Define the CronTriggerBean trigger -->
<Bean id = "mathsTriggerBean" class = "org. springframework. scheduling. quartz. CronTriggerBean">
<! -- Inject the job to be started -->
<Property name = "jobDetail">
<Ref bean = "mathsJob1"/>
</Property>
<! -- Trigger rule, which is triggered at every day -->
<Property name = "cronExpression">
<Value> 0 0 1 **? </Value>
</Property>
</Bean>

<! -- Define job -->
<Bean name = "mathsJob1"
Class = "org. springframework. scheduling. quartz. MethodInvokingJobDetailFactoryBean">
<! -- Injected service layer -->
<Property name = "targetObject" ref = "mathsService"/>
<! -- Call Method -->
<Property name = "targetMethod" value = "aotoMathsMethod1"/>
<! -- If concurrent is true, a QuartzJob can be executed concurrently. Otherwise, the job is executed sequentially. -->
<Property name = "concurrent" value = "false"/>
</Bean>
 
<! -- Define the CronTriggerBean trigger -->
<Bean id = "mathsTriggerBean" class = "org. springframework. scheduling. quartz. CronTriggerBean">
<! -- Inject the job to be started -->
<Property name = "jobDetail">
<Ref bean = "mathsJob1"/>
</Property>
<! -- Trigger rule, which is triggered at every day -->
<Property name = "cronExpression">
<Value> 0 0 1 **? </Value>
</Property>
</Bean>
 

 

 

2. SimpleTriggerBean

[Html]
<! -- Define job -->
<Bean name = "mathsJob2"
Class = "org. springframework. scheduling. quartz. MethodInvokingJobDetailFactoryBean">
<! -- Injected service layer -->
<Property name = "targetObject" ref = "mathsService"/>
<! -- Call Method -->
<Property name = "targetMethod" value = "aotoMathsMethod2"/>
<! -- If concurrent is true, a QuartzJob can be executed concurrently. Otherwise, the job is executed sequentially. -->
<Property name = "concurrent" value = "false"/>
</Bean>

<! -- Define SimpleTriggerBean trigger -->
<Bean id = "mathsTriggerBean" class = "org. springframework. scheduling. quartz. SimpleTriggerBean">
<! -- Inject the job to be started -->
<Property name = "jobDetail">
<Ref bean = "mathsJob2"/>
</Property>
<! -- Start after 30 s -->
<Property name = "startDelay" value = "30000"/>
<! -- 10 s check -->
<Property name = "repeatInterval" value = "2*60*60*1000"/>
</Bean>

<! -- Define job -->
<Bean name = "mathsJob2"
Class = "org. springframework. scheduling. quartz. MethodInvokingJobDetailFactoryBean">
<! -- Injected service layer -->
<Property name = "targetObject" ref = "mathsService"/>
<! -- Call Method -->
<Property name = "targetMethod" value = "aotoMathsMethod2"/>
<! -- If concurrent is true, a QuartzJob can be executed concurrently. Otherwise, the job is executed sequentially. -->
<Property name = "concurrent" value = "false"/>
</Bean>
 
<! -- Define SimpleTriggerBean trigger -->
<Bean id = "mathsTriggerBean" class = "org. springframework. scheduling. quartz. SimpleTriggerBean">
<! -- Inject the job to be started -->
<Property name = "jobDetail">
<Ref bean = "mathsJob2"/>
</Property>
<! -- Start after 30 s -->
<Property name = "startDelay" value = "30000"/>
<! -- 10 s check -->
<Property name = "repeatInterval" value = "2*60*60*1000"/>
</Bean>
 

 

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.