线程池实现多线程
public class RunnableImpDemo implements Runnable { @Override public void run() { System.out.println(Thread.currentThread().getName()); } }
import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class ThreadPoolDemo { public static void main(String[] args) { ExecutorService es= Executors.newFixedThreadPool(3); for(int i=0;i<5;i++){ es.submit(new RunnableImpDemo()); } es.shutdown(); } }