Tekkaman

导航

 

线程池

1、固定大小线程池

  import java.util.concurrent.Executors; 
  import java.util.concurrent.ExecutorService; 

  ExecutorService pool = Executors.newFixedThreadPool(2); 

  pool.execute(t1); 

  pool.shutdown(); 

2、单任务线程池

  ExecutorService pool = Executors.newSingleThreadExecutor();

3、可变尺寸线程池

  ExecutorService pool = Executors.newCachedThreadPool(); 

4、延迟连接池

  import java.util.concurrent.Executors; 
  import java.util.concurrent.ScheduledExecutorService; 
  import java.util.concurrent.TimeUnit; 

  ScheduledExecutorService pool = Executors.newScheduledThreadPool(2); 

  pool.schedule(t4, 10, TimeUnit.MILLISECONDS); 

5、单任务延迟连接池

  ScheduledExecutorService pool = Executors.newSingleThreadScheduledExecutor();

posted on 2011-06-01 12:26  Tekkaman  阅读(525)  评论(0编辑  收藏  举报