`

spring2 计划任务

阅读更多

http://docs.huihoo.com/spring/2.0.x/zh-cn/scheduling.html

 

1.<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
  <property name="corePoolSize" value="5" />
  <property name="maxPoolSize" value="10" />
  <property name="queueCapacity" value="25" />
</bean>

2.public class Test {

 public static void main(String[] args) {
  ApplicationContext app=new ClassPathXmlApplicationContext("app*.xml");

 

 FileReaderThread frt=(FileReaderThread)app.getBean("read");
  FileWriterThread fwt=(FileWriterThread)app.getBean("write");

 

TaskExecutor task=(TaskExecutor)app.getBean("taskExecutor");
  task.execute(frt);
  task.execute(fwt);  //两次调用才看起来象是线程
  
  task.execute(frt);
  task.execute(fwt);//必须加上

}

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics