spring 定时器的使用,可以用来发送垃圾邮件,或者定时搜索东西(附源码)

spring 定时器的使用,可以用来发送垃圾邮件,或者定时搜索东西(附源码)


<beans>

 <bean id="timer" class="org.springframework.scheduling.timer.TimerFactoryBean">
  <property name="scheduledTimerTasks">
   <list>
    <ref local="testtimertask"/>
   </list>
  </property>
 </bean>

 <bean id="timerbean" class="MyTimerImpl">

 </bean>
 <bean id="testtimertask" class="org.springframework.scheduling.timer.ScheduledTimerTask">
  <property name="timerTask">
   <ref bean="timerbean" />
  </property>

  <property name="delay">
   <value>1000</value>
  </property>

  <property name="period">
   <value>1000</value>
  </property>

 </bean>

</beans>

MyTimerImpl

import java.util.TimerTask;

public class MyTimerImpl  extends TimerTask {

 public void run() {
  System.out.println("aaaaaaaa");
  
 }
TestTimer

import net.loocky.sowq.util.ServiceFactory;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class TestTimer {

 /**
  * @param args
  */
 public static void main(String[] args) throws Exception {
  
    ApplicationContext ctx=new FileSystemXmlApplicationContext("E:\\work\\Test\\bin\\spring-config.xml");
  Thread.sleep(100000);
 }

}

}

你可能感兴趣的:(spring 定时器的使用,可以用来发送垃圾邮件,或者定时搜索东西(附源码))