java5 新增线程池的使用

  1. package net.itdos.concurrent;  
  2.   
  3. import java.util.concurrent.ExecutorService;  
  4. import java.util.concurrent.Executors;  
  5. import java.util.concurrent.atomic.AtomicInteger;  
  6.   
  7. public class TestConcurrent {  
  8.     java.util.concurrent.atomic.AtomicInteger mm = new AtomicInteger(4);  
  9.     public void gg(){  
  10.         ExecutorService pool = Executors.newFixedThreadPool(5);  
  11.         for(int i = 0; i <10 ;i++){  
  12.             final int gg = i;  
  13.             pool.execute(new Runnable() {  
  14.                   
  15.                 @Override  
  16.                 public void run() {  
  17.                     // TODO Auto-generated method stub   
  18.                     System.out.println(Thread.currentThread().getName() + ":"+gg);  
  19.                 }  
  20.             });  
  21.         }  
  22.         pool.shutdown();  
  23.           
  24.     }  
  25.     public static void main(String[] kl){  
  26.         new TestConcurrent().gg();  
  27.     }  
  28. }  

猜你喜欢

转载自baobeituping.iteye.com/blog/1399150