spring-thread pool (2)

Source: Internet
Author: User

Inheritance: http://www.cnblogs.com/crazylqy/p/4220743.html

Spring settings container starts when the thread class is run (can be executed cyclically)

Modify the following two files,

1.spring setting container Run Thread class at startup

<?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/beanshttp//www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp//Www.springframework.org/schema/contexthttp//www.springframework.org/schema/context/spring-context-3.0.xsd "><!--managed thread--><bean id= "Messageprintertask"class= "Messageprintertask" > </bean> <!--This sets up the container to automatically run a thread start-to-<bean id= " Springscheduleexecutortask "class= "Org.springframework.scheduling.concurrent.ScheduledExecutorTask" > <property name= "runnable" ref= " Messageprintertask "/><!--messageprintertask for thread class--<!--container is loaded after 10 seconds to execute--<property name=" de Lay "value=" 10000 "/> <!--each task interval of 5 seconds, loop execution of the thread, delete the setting only once when the container starts and <property name=" period "value=" 5000 "/> </bean> <bean id=" Springscheduledexecutorfactorybean "class= "Org.springframework.scheduling.concurrent.ScheduledExecutorFactoryBean" > <property name= " Scheduledexecutortasks "> <list> <ref bean=" Springscheduleexecutortask "/> </list&      Gt </property> </bean> <!--This sets up the container to automatically run a thread end----</beans>


Test run

Import Org.springframework.context.ApplicationContext; Import Org.springframework.context.support.ClassPathXmlApplicationContext; /**  */Publicclass  App    {publicstatic  void  Main (string[] args)    {        new Classpathxmlapplicationcontext (" Applicationcontext.xml ");}        }

Results

spring-thread pool (2)

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.