* newFixedThreadPool:创建固定大小的线程池,每次提交一个任务就创建一个线程,直到数量达到线程池的最大数量。数量一旦到达最大, * 就会保持不变,如果出现异常,会补充一个新的线程 */ public class ThreadPool { public static void main(String[] args) { //创建线程池(4种) //第二种:创建一个固定大小的线程池 ExecutorService es = Executors.newFixedThreadPool(10); es.execute(new MyRunnable6()); es.execute(new MyRunnable6()); es.execute(new MyRunnable6()); es.execute(new MyRunnable6()); es.execute(new MyRunnable6()); es.execute(new MyRunnable6()); es.execute(new MyRunnable6()); es.execute(new MyRunnable6()); es.execute(new MyRunnable6()); es.execute(new MyRunnable6()); es.shutdown(); } } class MyRunnable6 implements Runnable{ @Override public void run() { for (int i = 0; i < 20; i++) { System.out.println(Thread.currentThread().getName()+"->"+i); try { Thread.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); } } } }