当前位置:网站首页>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: 默认线程工厂
边栏推荐
- 杰理之添加定时器中断【篇】
- Codeforces Round #786 (Div. 3) ABCDE
- R language uses GLM function to build Poisson logarithm linear regression model, processes three-dimensional contingency table data to build saturation model, uses step function to realize stepwise re
- C语言0长度数组的妙用
- 【TcaplusDB知识库】TcaplusDB单据受理-创建游戏区介绍
- Proe/Creo家电产品结构设计规范-电煎锅
- 2022CISCN华中 Web
- Youboxun attended the openharmony technology day to create a new generation of secure payment terminals
- Naacl 2022 | TAMT: search the transportable Bert subnet through downstream task independent mask training
- Excel中输入整数却总是显示小数,如何调整?
猜你喜欢

Peak store app imitation station development play mode explanation source code sharing

StarCraft's Bug King ia retired for 2 years to engage in AI, and lamented that it was inferior
![21: Chapter 3: develop pass service: 4: further improve [send SMS, interface]; (in [send SMS, interface], call Alibaba cloud SMS service and redis service; a design idea: basecontroller;)](/img/a7/ce0dc8e53569703aa02843f1fc1cf4.png)
21: Chapter 3: develop pass service: 4: further improve [send SMS, interface]; (in [send SMS, interface], call Alibaba cloud SMS service and redis service; a design idea: basecontroller;)

Wait, how do I use setmemorylimit?

杰理之DAC输出方式设置【篇】
![[tcaplusdb knowledge base] Introduction to tcaplusdb tcaplusadmin tool](/img/ba/f865c99f3ea9e42c85b7e906f4f076.png)
[tcaplusdb knowledge base] Introduction to tcaplusdb tcaplusadmin tool

进程间通信详解

Detailed explanation of interprocess communication

I.MX6ULL启动方式

One copy ten, CVPR oral is accused of plagiarizing a lot
随机推荐
C語言0長度數組的妙用
In depth analysis of error solutions and problems in dynamic loading of unity shadow and outline components
杰理之添加定时器中断【篇】
R language uses the poisgof function of epidisplay package to test the goodness of fit of Poisson regression and whether there is overdispersion
政策关注 | 加快构建数据基础制度,维护国家数据安全
【TcaplusDB知识库】TcaplusDB单据受理-建表审批介绍
R语言使用MASS包的polr函数构建有序多分类logistic回归模型、使用VGAM包的vglm函数对有序多分类logistic回归模型进行平行性假设作检验
优博讯出席OpenHarmony技术日,全新打造下一代安全支付终端
Jerry's DAC output mode setting [chapter]
ECMAScript 6(es6)
QStyle实现自绘界面项目实战(一)
i.mx6ull(单片机) c语言环境搭建
pull request
Jerry's seamless looping [chapter]
The R language uses the DOTPLOT function of epidisplay package to visualize the frequency of data points in different intervals in the form of point graph, specifies the grouping parameters with the b
防止被00后整顿?一公司招聘要求员工不能起诉公司
Summary of qstype class usage (III)
Jerry's adding timer interrupt [chapter]
干货!零售业智能化管理会遇到哪些问题?看懂这篇文章就够了
[tcapulusdb knowledge base] Introduction to tcapulusdb table data caching