上次说要写一篇关于统一线程池的文章,拖了好久,下午就来写一写,温故而知新。
线程池机制大家都很熟悉,把任务添加到池中,然后按照一定的机制使用多个线程来执行任务。在java中通常是使用以下代码来创建。newCachedThreadPool()是内置的几种获取池的方法。注释说:Creates a thread pool that creates new threads as needed, but will reuse previously constructed threads when they are available. These pools will typically improve the performance of programs that execute many short-lived asynchronous tasks. 创建一个可以线程重用的池,线程在需要时创建。在执行大量短期异步的任务时通常可以提高性能。更多信息请见线程池