public class CachedthreadPool { public static void main(String[] args) { ExecutorService es = Executors.newCachedThreadPool(); for ( int i = 0; i< 5; i++) es.execute(new LiftOff()); es.shutdown(); } }
public class MoreBasicThread {
/** * @param args */ public static void main(String[] args) { for (int i = 0; i< 5; i++) { new Thread(new LiftOff()).start(); } System.out.println("Waiting for liftOff"); }
}
public class SingleThreadExecutor { public static void main(String[] args) { // 保证无论何时都只有一个线程在运行。 ExecutorService es = Executors.newSingleThreadExecutor(); for(int i = 0; i < 5; i++) { es.execute(new LiftOff()); } es.shutdown(); } }
[code="java"]public class CachedthreadPool { public static void main(String[] args) { ExecutorService es = Executors.newCachedThreadPool(); for ( int i = 0; i< 5; i++) es.execute(new Lif...