版权声明:本文为博主林炳文Evankaka原创文章,转载请注明出处http://blog.csdn.net/evankaka
);
验证实例:
[java] view plain copy
- public static void testCachedThreadPool() {
- System.out.println("Main: Starting at: "+ new Date());
- ExecutorService exec = Executors.newCachedThreadPool(); //创建一个缓冲池,缓冲池容量大小为Integer.MAX_VALUE
- for(int i = 0; i < 10; i++) {
- exec.execute(new Handle(String.valueOf(i)));
- }
- exec.shutdown(); //执行到此处并不会马上关闭线程池,但之后不能再往线程池中加线程,否则会报错
- System.out.println("Main: Finished all threads at"+ new Date());
- }
执行结果:
从上面的结果可以看出:
);
运行结果:
; i < 10; i++) {