java线程池

package senior;

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

public class TestPool {
	public static void main(String[] args) {
		ExecutorService service = Executors.newFixedThreadPool(10);
		service.execute(new MyThread());
		service.execute(new MyThread());
		service.execute(new MyThread());
		service.execute(new MyThread());
		service.execute(new MyThread());
		service.execute(new MyThread());
		service.execute(new MyThread());
		service.execute(new MyThread());
		service.execute(new MyThread());
		service.execute(new MyThread());
		service.execute(new MyThread());
		service.execute(new MyThread());
		service.execute(new MyThread());
		service.execute(new MyThread());
		service.execute(new MyThread());
		service.execute(new MyThread());
		service.execute(new MyThread());
		service.execute(new MyThread());
		service.execute(new MyThread());
		service.execute(new MyThread());
		service.execute(new MyThread());
		service.execute(new MyThread());
		service.shutdown();
	}
}
class MyThread implements Runnable{

	@Override
	public void run() {
		// TODO Auto-generated method stub
		for (int i = 0; i < 1; i++) {
			System.out.println(Thread.currentThread().getName()+"\t"+i);
		}
	}
	
}

pool-1-thread-3 0
pool-1-thread-7 0
pool-1-thread-2 0
pool-1-thread-6 0
pool-1-thread-5 0
pool-1-thread-4 0
pool-1-thread-1 0
pool-1-thread-10 0
pool-1-thread-9 0
pool-1-thread-8 0
pool-1-thread-6 0
pool-1-thread-7 0
pool-1-thread-3 0
pool-1-thread-6 0
pool-1-thread-9 0
pool-1-thread-6 0
pool-1-thread-8 0
pool-1-thread-3 0
pool-1-thread-10 0
pool-1-thread-1 0
pool-1-thread-7 0
pool-1-thread-4 0

上一篇:九、std::async异步线程


下一篇:进程和线程