Spring MVC implements multiple timer tasks in a timer class

Source: Internet
Author: User

Spring MVC implements multiple timer tasks in a timer class


1. Create a new timer configuration file, called Spring-task.xml, which reads as follows:

<?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"

Xmlns:mvc= "Http://www.springframework.org/schema/mvc" xmlns:tx= "Http://www.springframework.org/schema/tx"

xmlns:task= "Http://www.springframework.org/schema/task"

Xsi:schemalocation= "Http://www.springframework.org/schema/beans

Http://www.springframework.org/schema/beans/spring-beans-3.1.xsd

Http://www.springframework.org/schema/context

Http://www.springframework.org/schema/context/spring-context-3.1.xsd

Http://www.springframework.org/schema/tx

Http://www.springframework.org/schema/tx/spring-tx-3.1.xsd

Http://www.springframework.org/schema/task

Http://www.springframework.org/schema/task/spring-task-3.1.xsd ">


<bean id= "Midtask" class= "Com.afmobi.task.MidTask"/>

<!--register Timer class, later---

<!--Timer 1 begin-->

<bean id= "Middowntaskinfo"

class= "Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" >

<property name= "TargetObject" ref= "Midtask"/>

<property name= "Targetmethod" value= "Midownloaditemtask"/>

<!--Specify the method name to be executed by the Timer task class This is midownloaditemtask---

</bean>

<bean id= "Middowntrigger" class= "Org.springframework.scheduling.quartz.CronTriggerBean" >

<!--Scheduler to configure Timer tasks--

<property name= "Jobdetail" ref= "Middowntaskinfo"/>

<property name= "cronexpression" value= "0 0" * *? "/>

<!--default daily 1 o'clock in the morning

</bean>


<!--Timer 2 begin-->

<bean id= "Midstatustaskinfo"

class= "Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" >

<property name= "TargetObject" ref= "Midtask"/>

<property name= "Targetmethod" value= "Midownloadstatustask"/>

</bean>

<bean id= "Midstatustasktrigger" class= "Org.springframework.scheduling.quartz.CronTriggerBean" >

<property name= "Jobdetail" ref= "Midstatustaskinfo"/>

<property name= "cronexpression" value= "0 * *?"/>

<!--daily 1:10 A.M.

</bean>


<!--Register Listener--

<bean id= "Registerquartz"

class= "Org.springframework.scheduling.quartz.SchedulerFactoryBean" >

<!--Register Timer entity Collection--

<property name= "Triggers" >

<list>

<ref local= "Middowntrigger"/>

<ref local= "Midstatustasktrigger"/>

</list>

</property>

</bean>

</beans>


2. Introduce this XML file in spring's main configuration file:

<import resource= "Spring-task.xml"/><!--Timer configuration file--


3. Timer Implementation class: (The method of implementing 2 timers)


public class Midtask {


@Autowired

Private Taskservice Taskservice;

/**

* Download Product Intermediate table mid_download_item_yyyy_mm Scheduled Tasks

*/

private void Midownloaditemtask () {

List List = Taskservice.downloadfinishlist ();

}

/**

* Download Status Intermediate table Mid_date_download_status Scheduled Tasks

*/

private void Midownloadstatustask () {

List List = Taskservice.downloadstatuslist ();

}

}


To this end, (as for the missing jar package or something here do not explain, error, you go to download the corresponding jar on the Internet OK. )


This article is from the "re-learn Java" blog, please be sure to keep this source http://3131854.blog.51cto.com/3121854/1566381

Spring MVC implements multiple timer tasks in a timer class

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.