ITeye博客

Java中的线程池简单实现

pskfire · 2012-11-22 21:46 · Java · 编程语言 · Markdown


package com.threadPool.executiveService;

public class MyThread implements Runnable{

	@Override
	public void run() {
		for(int i=0; i<100; i++) {
			System.out.println(Thread.currentThread().getName() + "i = " + i);
		}
	}

}


package com.threadPool.executiveService;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadPoolTest {

	public static void main(String[] args) {
		ExecutorService threadPool = Executors.newFixedThreadPool(6);
		threadPool.submit(new MyThread());
		threadPool.submit(new MyThread());
		threadPool.submit(new MyThread());
		threadPool.shutdown();
	}
}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。