线程池
- 基本应用
public class Demo { public static void main(String[] args) throws IOException, InterruptedException { ExecutorService pool = Executors.newFixedThreadPool(2); pool.submit(new MyRunnable()); pool.submit(new MyRunnable()); pool.shutdown(); // 关闭线程池 } } class MyRunnable implements Runnable { @Override public void run() { for (int i = 0; i < 10; i++) { System.out.println(Thread.currentThread().getName() + "....." + i); } } }