package test1;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* 通过以下代码可看出,线程池0-2用完后,释放,再放入3-5,如此循环,直到走完全部循环
* @author Administrator
*
*/
public class ExecutorServiceTest {
public static void main(String[] args) {
ExecutorServiceTest test = new ExecutorServiceTest();
test.init();
}
private void init() {
ExecutorService es = Executors.newFixedThreadPool(3);
for (int i = 0; i < 10; i++) {
final int a = i;
es.execute(new Runnable() {
@Override
public void run() {
for (int i = 0; i < 5; i++) {
System.out.println("线程池 " + a + " 的" + Thread.currentThread().getName() + "第" + i + "次循环");
}
}
});
}
}
}
标签:int,代码,ExecutorServiceTest,用法,public,ExecutorService,void,es From: https://blog.51cto.com/u_21817/6066949