spring 线程池

阅读更多

spring4 线程池:把需要执行的Thread放入线程池中:缓冲队列


 
  
  
  
  
  
  
  
  
  
  
  
   

   

   

   
   
  
 

 
 public class Test {
 
 public static void main(String[] args) {
 ApplicationContext app = new ClassPathXmlApplicationContext("applicationContext.xml");
 
 ThreadPoolTaskExecutor pool=(ThreadPoolTaskExecutor)app.getBean("taskExecutor");
  
 testSpringThreadPool(pool);
 }
 
 static void testSpringThreadPool(ThreadPoolTaskExecutor pool){
  
  pool.execute(new TestThread(0));
  for(int i=1;i<10000;i++){
   pool.execute(new TestThread(i));
  }
 }

 static class TestThread implements Runnable{
  private int num;
  
  public TestThread(int num){
   this.num=num;
  }

  public void run() {
   
   try {
    Thread.sleep(200);
   } catch (InterruptedException e) {
    e.printStackTrace();
   }
   System.out.println("thread "+num);
  }
  
 }
 
 
 
 
 

你可能感兴趣的:(spring)