package 多线程练习; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class 线程池 { public static void main(String[] args) { Runnable rb =()->{ System.out.println(Thread.currentThread().getName()); }; // 创建线程池 ExecutorService service = Executors.newFixedThreadPool(10); // 调用 execute是执行thread跟runnable 无返回值 submit是调用callable有返回值的 service.execute(rb); service.execute(rb); service.execute(rb); service.execute(rb); service.execute(rb); service.execute(rb); service.execute(rb); service.shutdown(); } }
输出结果