1 哲学家思维
线程池类比银行网点的情况
package threadpoolexecutor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class Fixed {
public static void main(String[] args) throws InterruptedException {
// ExecutorService executorService = Executors.newFixedThreadPool(5);
// ExecutorService executorService = Executors.newSingleThreadExecutor();
ExecutorService executorService = Executors.newCachedThreadPool();
for (int i = 1; i <=10; i++) {
executorService.execute(()->{
System.out.println(Thread.currentThread().getName()+"正在执行这个任务!");
});
//想一下,如果业务没那么着急,是不是不用再招聘更多的业务员来处理业务?因为业务员处理完上一个以后
//可以接着处理其他的。但是比较差的点就是处理效率不高。打印效果显示一个业务员就可以处理完这十个任务
//代价是需要10秒钟来处理
TimeUnit.SECONDS.sleep(1);
}
}
}
2、学习思考方式
(1) 理论、实践、小总结;
(2) 知识、证明、排查修复;
知易行难---多实践



