标签:cut led 结束 exe LEDE cond 大小 周期性 system
线程池的作用是什么
如果没有线程池,用户的每一个请求都会经历申请资源创建线程,执行线程,释放资源销毁线程这个过程,很多时间浪费在创建和销毁这两件事情上。如果用户请求时线程已经存在,用户使用线程结束也不用去考虑如何销毁,由于减少了每个任务调用的开销,它们通常可以在执行大量异步任务时提供增强的性能,并且还可以提供绑定和管理资源的方法。线程池中的线程可以多次重用,这与数据库连接池是相同的逻辑。常见的线程池有:
ExecutorService executorService = Executors.newFixedThreadPool(1);
executorService.submit(new Runnable() {
@Override
public void run() {
System.out.println("newFixedThreadPool");
}
});
executorService.shutdown();
ExecutorService executorService = Executors.newCachedThreadPool();
executorService.submit(new Runnable() {
@Override
public void run() {
System.out.println("newFixedThreadPool");
}
});
executorService.shutdown();
ExecutorService executorService = Executors.newSingleThreadExecutor();
executorService.submit(new Runnable() {
@Override
public void run() {
System.out.println("newFixedThreadPool");
}
});
executorService.shutdown();
ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
executorService.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
System.out.println("newScheduledThreadPool");
}
},5,2,TimeUnit.SECONDS);
标签:cut led 结束 exe LEDE cond 大小 周期性 system
原文地址:https://www.cnblogs.com/alichengxuyuan/p/12599988.html