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)