java JUC线程池:Executors.newFixedThreadPool代码示例
原创
©著作权归作者所有:来自51CTO博客作者a772304419的原创作品,请联系作者获取转载授权,否则将追究法律责任
package com.zxl.juc;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class FixedThreadPoolDemo1 {
public static void main(String[] args) {
ExecutorService executorService = Executors.newFixedThreadPool(3);
for (int i = 0; i < 10; i++) {
executorService.submit(()->{
System.out.println(Thread.currentThread().getName());
});
}
}
}
pool-1-thread-1
pool-1-thread-3
pool-1-thread-2
pool-1-thread-1
pool-1-thread-3
pool-1-thread-2
pool-1-thread-3
pool-1-thread-1
pool-1-thread-3
pool-1-thread-2