当前位置:网站首页>Fork/Join 框架基本使用和原理
Fork/Join 框架基本使用和原理
2022-06-27 11:30:00 【外星喵】
ForkJoin 线程池框架回顾
ForkJoin 框架其实就是一个线程池 ExecutorService 的实现,通过工作窃取(work-stealing)算法,获取其他线程中未完成的任务来执行。
可以充分利用机器的多处理器优势,利用空闲的线程去并行快速完成一个可拆分为小任务的大任务,类似于分治算法。
ForkJoin 的目标,就是利用所有可用的处理能力来提高程序的响应和性能。本文将介绍 ForkJoin 框架,源码剖析。
ForkJoinPool 核心类实现
ForkJoin 框架的核心是 ForkJoinPool 类,基于 AbstractExecutorService 扩展。
ForkJoinPool 中维护了一个队列数组 WorkQueue[],每个 WorkQueue 维护一个 ForkJoinTask 数组和当前工作线程。
ForkJoinPool 实现了工作窃取(work-stealing)算法并执行 ForkJoinTask。
ForkJoinPool,所有线程和 WorkQueue 共享,用于工作窃取、任务状态和工作状态同步。
核心属性介绍
ADD_WORKER: 100000000000000000000000000000000000000000000000 -> 1000 0000 0000 0000,用来配合 ctl 在控制线程数量时使用
ctl: 控制 ForkJoinPool 创建线程数量,(ctl & ADD_WORKER) != 0L 时创建线程,也就是当 ctl 的第 16 位不为 0 时,可以继续创建线程
defaultForkJoinWorkerThreadFactory: 默认线程工厂
边栏推荐
- Summary of qstype class usage (II)
- 最大路径和问题(摘樱桃问题)
- 【TcaplusDB知识库】TcaplusDB OMS业务人员权限介绍
- Nvme2.0 protocol - new features
- 【TcaplusDB知识库】TcaplusDB-tcaplusadmin工具介绍
- Uniform Asymptotics by Alexei
- One copy ten, CVPR oral is accused of plagiarizing a lot
- 等等, 怎么使用 SetMemoryLimit?
- Excel中输入整数却总是显示小数,如何调整?
- Leetcode 177 The nth highest salary (June 26, 2022)
猜你喜欢

C语言0长度数组的妙用

从零开始搭建物联网系统

Unity Shader学习(一)认识unity shader基本结构

JSP custom tag

Oracle-分组统计查询

Code for structural design of proe/creo household appliances - electric frying pan

Summary of qstype class usage (III)

Popular science of device review: popular science of innovative medical device series - sternum plate products

JSP自定义标签
![[tcaplusdb knowledge base] Introduction to tcaplusdb tcaplusadmin tool](/img/ba/f865c99f3ea9e42c85b7e906f4f076.png)
[tcaplusdb knowledge base] Introduction to tcaplusdb tcaplusadmin tool
随机推荐
[tcapulusdb knowledge base] tcapulusdb operation and maintenance doc introduction
器审科普:创新医疗器械系列科普——胸骨板产品
pull request
一篇抄十篇,CVPR Oral被指大量抄袭
Matlab exercises - create 50 rows and 50 columns of all zero matrix, all 1 matrix, identity matrix, diagonal matrix, and output the 135 element of the matrix.
信息学奥赛一本通 1332:【例2-1】周末舞会
Jerry's adding timer interrupt [chapter]
【TcaplusDB知识库】TcaplusDB单据受理-创建业务介绍
【TcaplusDB知识库】TcaplusDB业务数据备份介绍
Redis distributed lock 15 ask, what have you mastered?
杰理之睡眠以后定时唤醒系统继续跑不复位【篇】
Unity shader learning (II) the first shader
等等, 怎么使用 SetMemoryLimit?
c/s 架构
[tcapulusdb knowledge base] tcapulusdb doc acceptance - create business introduction
L'utilisation de C language 0 length Array
Informatics Olympiad all in one 1332: [example 2-1] weekend dance
机器学习系统在生产中的挑战
Microsoft cloud technology overview
"24 of the 29 students in the class successfully went to graduate school" rushed to the hot search! Where are the remaining five?