🕐 线程池

```java public class MyRunnable implements Runnable { @Override public void run() { for (int i = 0; i <10 ; i++) { System.out.println(Thread.currentThread().getName()+"---"+i); } } } ``` ```java public class RunTest { public static void main(String[] args) throws InterruptedException { //创建无限的线程池对象 //ExecutorService threadPool = Executors.newCachedThreadPool(); //创建有限的线程池对象 ExecutorService threadPool1 = Executors.newFixedThreadPool(2); //提交任务 threadPool1.submit(new MyRunnable()); threadPool1.submit(new MyRunnable()); threadPool1.submit(new MyRunnable()); threadPool1.submit(new MyRunnable()); //销毁线程池 threadPool1.shutdown(); } } ```