7

并发笔记-ThreadPoolExecutor详解

 2 years ago
source link: https://mikeygithub.github.io/2022/05/30/yuque/ymxl5b/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

并发笔记-ThreadPoolExecutor详解 - 麦奇

并发笔记-Thre_

Mikey 2022年5月30日 下午

282 字

3 分钟

4 次

image_副本.png

ThreadPoolExecutor 一种 ExecutorService,使用可能的多个池线程之一执行每个提交的任务,通常使用 Executors 工厂方法进行配置。
线程池解决了两个不同的问题:它们通常在执行大量异步任务时提供更好的性能,这是因为减少了每个任务的调用开销;它们还提供了一种方法来限制和管理执行任务集合时消耗的资源,包括线程。每个 ThreadPoolExecutor 还维护一些基本统计信息,例如已完成任务的数量。

为了在广泛的上下文中有用,这个类提供了许多可调整的参数和可扩展性挂钩。然而,我们敦促程序员使用更方便的 Executors 工厂方法 Executors。newCachedThreadPool(无边界线程池,具有自动线程回收),执行器。newFixedThreadPool(固定大小的线程池)和执行器。newSingleThreadExecutor(单后台线程),为最常见的使用场景预配置设置。否则,在手动配置和调优此类时,请使用以下指南:

image.png
  1. https://people.apache.org/~tellison/classlib_doc/html/classjava_1_1util_1_1concurrent_1_1ThreadPoolExecutor.html

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK