public class MyThreadPoolDemo {
ExecutorService executorService;
public static void main(String[] args) {
MyThreadPoolDemo myThreadPoolDemo = new MyThreadPoolDemo();
myThreadPoolDemo.rep(myThreadPoolDemo.three());
}
public ExecutorService one(){
return executorService = Executors.newFixedThreadPool(5);
}
public ExecutorService two(){
return executorService = Executors.newSingleThreadExecutor();
}
public ExecutorService three(){
return executorService = Executors.newCachedThreadPool();
}
public void rep(ExecutorService executorService){
for (int i = 0; i < 10; i++) {
executorService.execute(()->{
System.out.println(Thread.currentThread().getName()+"\t 顾客办理业务");
});
}
executorService.shutdown();
}
}