import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; /** * 一个最简单的线程池,这个模型很简单,但是很有用 * * @author leizhimin 2014/8/22 20:21 */ public class Test3 { private static final ExecutorService threadPool = Executors.newFixedThreadPool(1); public static void main(String[] args) throws InterruptedException { for (int i = 0; i < 10000; i++) { final int finalI = i; Runnable r = new Runnable() { @Override public void run() { System.out.println(String.valueOf(finalI)+":"+System.currentTimeMillis()); } }; threadPool.submit(r); Thread.currentThread().sleep(300L); } } }
0:1409187082455 1:1409187082755 2:1409187083055 3:1409187083355 4:1409187083655 5:1409187083955 6:1409187084255 7:1409187084555 8:1409187084855 9:1409187085155 10:1409187085455 11:1409187085755 。。。
时间: 2024-10-14 00:56:00