3, spring new way to realize timing scheduling

Source: Internet
Author: User

1, implementation and cyclic scheduling similar

 Public class quartzjob3{    publicvoid  Test () {        simpledateformat sdf=new SimpleDateFormat ("HH:mm:ss");        System.out.println ("Spring new Method-using timed trigger-called" +sdf.format (new  Date ()));}    }  
2, spring configuration as follows (1) Injection scheduling class object (Inject 2 class objects, trigger in different ways)
class class= "action. QuartzJob3 "/>
(2) Injection task scheduling management class object
    <!--Configure the task scheduling management class object---     Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean ">        <property name=" TargetObject "ref=" QuartzJob2 "/>        <property name=" Targetmethod "value=" test "/>    </bean>        class= "Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" >        <property Name= "TargetObject" ref= "quartzJob3"/>        <property name= "Targetmethod" value= "test"/>    </bean >
(3) Defining a trigger (two triggers show the difference)
    <!--defining triggers-simple triggers--    class= "Org.springframework.scheduling.quartz.SimpleTriggerBean" >        <property name= "Jobdetail" ref= "methodInvoking1"/> <property        name= "Startdelay" value= "$"/>        <property name= "Repeatinterval" value= "$"/>    </bean>        <!--define triggers-timed triggers    -- Class= "Org.springframework.scheduling.quartz.CronTriggerBean" >        <property name= "Jobdetail" ref= " MethodInvoking2 "/>        <property name=" cronexpression "value=" 0 15 * * *? " />    </bean>
(4) Factory mode activation trigger
    <!--start Task--    class= "Org.springframework.scheduling.quartz.SchedulerFactoryBean" >        < Property name= "Triggers" >            <list>                <ref local= "Simpletrigger"/> <ref local=                " Crontrigger "/>            </list>        </property>    </bean>  
3. Test class
    <!--start Task--    class= "Org.springframework.scheduling.quartz.SchedulerFactoryBean" >        <property name= "triggers" >            <list>                <ref local= "Simpletrigger"/>                <ref local= " Crontrigger "/>            </list>        </property>    </bean>  
4, the operation results can be seen in the 16:15 time triggered by the timing trigger

3, spring new way to realize timing scheduling

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.