当前位置:网站首页>[concurrent programming] concurrent tool class of thread
[concurrent programming] concurrent tool class of thread
2022-07-03 08:32:00 【keeper42】
Fork-Join
Divide and conquer algorithm ( Divide and rule )
The scale is N The problem of ,N< threshold , Direct solution ,N> threshold , take N Decompose into K A small mold problem , The subproblems are independent of each other , The same form as the original problem , The solutions of the subproblem are combined to obtain the solution of the original problem
Dynamic specifications
Working secret
workStealing
Fork/Join The standard paradigm used
Common concurrent tool classes
CountDownLatch
effect : It is a group of threads that wait for other threads to complete their work before executing , Enhanced Edition join
await To wait for (join),countDown Take charge of the subtraction of the counter
CyclicBarrier
Let a group of threads reach a barrier , Blocked , Until the last thread in the group reaches the barrier , The barrier is open , All blocked threads will continue to run CyclicBarrier(int parties)
await It can be used repeatedly
CyclicBarrier(int parties, Runnable barrierAction), The barrier is open ,barrierAction The defined task will execute
CountDownLatch and CyclicBarrier Differentiation and analysis
1、countdownlatch Controlled by the third party ,CyclicBarrier Release is controlled by a set of threads themselves
2、countdownlatch Release conditions >= Number of threads ,CyclicBarrier Release conditions = Number of threads
Semaphore
Control the number of threads accessing a specific resource at the same time , Used in flow control
useful.acquire(); synchronized (pool) { conn = pool.removeFirst(); } useless.release(); |
Exchange
Data exchange between two threads
Callable、Future and FutureTask
isDone, end , Normal or abnormal end , Or cancel it yourself , return true;
isCancelled The task was canceled before it was completed , return true;
cancel(boolean):
- The task hasn't started yet , return false
- The mission has started ,cancel(true), Interrupt a running task , Interrupt success , return true,cancel(false), Don't interrupt the running tasks
- The task is over , return false
Processing of documents containing pictures and words : picture ( On the cloud ), It can be used future Go get the picture , The main thread continues to parse the text .
边栏推荐
猜你喜欢
Cloudcompare learning (1) - cloudcompare compilation and common plug-in implementation
MySQL 8
C course design employee information management system
Three characteristics
Unity4.3.1 engine source code compilation process
Unity interactive water ripple post-treatment
了解小程序的笔记 2022/7/3
梯度下降法求解BP神经网络的简单Demo
Jupyter remote server configuration and server startup
Creation of osgearth earth files to the earth ------ osgearth rendering engine series (1)
随机推荐
Simple demo of solving BP neural network by gradient descent method
Base64编码简介
【Rust笔记】02-所有权
About Wireshark's unsuccessful installation of npcap
【Rust 笔记】12-闭包
【K&R】中文第二版 个人题解 Chapter1
Unity multi open script
Unity editor expansion - draw lines
Golang time format sorting
Osgearth topographic shading map drawing
Compilation error: "not in executable format: file format not recognized"“
Unity editor expansion - controls, layouts
Huawei interview summary during the epidemic
UE4 source code reading_ Bone model and animation system_ Animation process
Kunlunbase meetup is waiting for you!
Delete the last character of the string in golang
Golang string segmentation, substitution and interception
GIS实战应用案例100篇(七十八)-多规合一数据库设计及数据入库
Markdown directory generation
Encoding and decoding of golang URL