标签:多线程
import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class Test { public static void main(String[] args) { //设置线程数 ExecutorService service = Executors.newFixedThreadPool(5); for(int i= 0;i<10;i++){ service.execute(new RunnableImpl(i)); } service.shutdown(); } private static class RunnableImpl implements Runnable { private int id; private RunnableImpl(int id) { this.id = id; } public void run() { System.out.println("开始执行" + id); try { Thread.sleep(2000); } catch (InterruptedException e) { // nothing to do } System.out.println(id + "执行完毕。"); } @Override public String toString() { return "线程" + id; } } }
标签:多线程
原文地址:http://microe.blog.51cto.com/3332651/1697410