Java Timer configuration information adopts Spring-quartz method

Source: Internet
Author: User


Timer in Java is more common, here to do a little sorting, mainly in the configuration of information collation

The follow-up will continue to add


<?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:context= "Http://www.springframework.org/schema/context"
Xsi:schemalocation= "
Http://www.springframework.org/schema/beans
Http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
Http://www.springframework.org/schema/context
Http://www.springframework.org/schema/context/spring-context-3.0.xsd ">


<bean id= "Unifyjob" class= "Cn.huimin100.pay.center.controller.trade.RefundController" ></bean>
<bean id= "Refundtask" class= "Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" >
<property name= "TargetObject" ref= "Unifyjob" ></property>
<property name= "Targetmethod" value= "Execute" ></property>
<property name= "Concurrent" value= "false" ></property>
</bean>
<bean id= "Refundtrigger" class= "Org.springframework.scheduling.quartz.CronTriggerFactoryBean" >
<property name= "Jobdetail" ref= "Refundtask" ></property>
<property name= "cronexpression" value= "0 0/2 * * *?" ></property>
</bean>


<!--timer execution-->
<bean id= "Schedulerfactory" class= "Org.springframework.scheduling.quartz.SchedulerFactoryBean" >
<property name= "Triggers" >
<list>
<ref bean= "Refundtrigger"/>
</list>
</property>
</bean>
</beans>


--------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------

Description: <bean id= "Unifyjob" class= "Cn.huimin100.pay.center.controller.trade.RefundController" ></bean> Indicates the location ID alias where the timer exists


<bean id= "Refundtask" class= "Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" >
<property name= "TargetObject" ref= "Unifyjob" ></property> the target object for the target timer
<property name= "Targetmethod" value= "Execute" ></property> indicates the execution method name of the timer
<property name= "Concurrent" value= "false" ></property> set itself
</bean>



<bean id= "Refundtrigger" class= "Org.springframework.scheduling.quartz.CronTriggerFactoryBean" >
<property name= "Jobdetail" ref= "Refundtask" ></property> specifies the task configuration of the timer
<property name= "cronexpression" value= "0 0/2 * * *?" Time interval for ></property> timer execution
</bean>


<bean id= "Schedulerfactory" class= "Org.springframework.scheduling.quartz.SchedulerFactoryBean" >
<property name= "Triggers" >
<list>
<ref bean= "Refundtrigger"/> Specifies the execution timer
</list>
</property>
</bean>


---------------------------------------------------------------------------


In the execution class controller class:


@RequestMapping ("/execute")
@ResponseBody public
Void execute () {
    refundservice.execute ();
}

----Method:


@Override public void Execute () {mdc.put ("title", "Perform a refund");
    Logger.info ("Perform timed tasks to find the file for refund at this time");
    Final file[] filesfinal = Fileutil.searchtimefile (Config.getrefundnew (), New Date ());
            if (Filesfinal.length > 0) {for (int i = 0; i < filesfinal.length; i++) {final int j = i;
                    New Thread () {public void run () {File file = Filesfinal[j];
                    Refundcreatemodel model = Jsonutil.jsontobean (fileutil.readfile (file), refundcreatemodel.class);
                    Logger.info ("Next single parameter:" + model.tostring ());
                    String channel = Jsonutil.jsontoarray (Model.getchannelgroup ()) [0] + "";
                    Logger.info ("Execution Channel: + channel +", execution method: "+ model.getmethodname () +", File name: "+ file.getname () +" Start Execution ");  Invokeutil.executeinvoke (Channel + "." + Refund.split (":") [0], Model.getmethodname (), New Object[]{model, File.getname (). Split ("_")[0]}, new Class[]{model.getclass (), string.class});
                Logger.info ("Execution channel:" + Channel + ", execution method:" + model.getmethodname () + ", File name:" + file.getname () + "execution complete");
        }}.start (); }
    }
}


-------------------------------------


Loading a configuration file in Web.xml


<!--load Spring configuration file-->
<context-param>
  <param-name>contextconfiglocation</param-name >
  <!--If you are listening for multiple files, use ', ' to separate-->
  <param-value>classpath:spring-context.xml,classpath: Spring-quartz.xml</param-value>
</context-param>


Follow-up supplement ...


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.