当前位置:网站首页>Concurrency of heap memory allocation
Concurrency of heap memory allocation
2022-06-24 22:27:00 【Nice2cu_ Code】
In the actual development process , Often create objects , As a virtual machine , Thread safety must be guaranteed . Generally speaking, virtual machines use two ways to ensure thread safety
One 、CAS + Failure to retry
CAS It is an implementation of optimistic lock , Each time you do not lock, it is assumed that there is no conflict to complete an operation , If the operation fails due to a conflict, try again , Until we succeed . See blog , Delivery address :Java Concurrent programming unlocked (CAS)
Two 、TLAB
TLAB Is in Java The garden of Eden in the heap space is divided for each Threads Of memory space , Specifically allocate memory in this area for objects created by this thread .
Its main purpose is to allocate memory in a concurrent environment , Reduce competition for memory space between threads , Speed up memory allocation .
TLAB In essence, it's still Java Heap , So in TLAB The object of the area , It can also be accessed by other threads .
If not used TLAB, Multiple threads executing concurrently create objects , When allocating memory , Are likely to Java Apply at the same location in the heap , This requires locking this part of the memory space or adopting CAS And other operations to ensure thread safety , That is, ensure that the region is allocated to only one thread .
Used TLAB after ,JVM In heap memory for each thread reserve A memory area , When reservation occurs , Need to lock or use CAS And so on , Avoid multiple threads reserving the same area . Once a region is assigned to a thread , After that, when the thread needs to allocate memory , Will give priority to applying in this area . This area is for this thread Allocate memory This operation is thread private , Therefore, locking and other operations are not required during allocation , This not only protects thread safety, but also improves the allocation speed .
Be careful : When the object created by this thread is greater than TLAB Memory remaining in or TLAB When I ran out of memory , Then use CAS + Failed to allocate memory by retry .
边栏推荐
- The leader of ERP software in printing industry
- In the first year of L2, arbitrum nitro was upgraded to bring more compatible and efficient development experience
- I really can't do it. After 00, I collapsed and wanted to leave
- How does flutter use the online transcoding tool to convert JSON to model
- 如何提取网页中的日期?
- NiO, bio, AIO
- 解决dataframe报错ValueError: Cannot take a larger sample than population when ‘replace=False‘
- leetcode:45. 跳跃游戏 II【经典贪心】
- Disk structure
- Seven principles of software design
猜你喜欢

I really want to send a bunch of flowers

虚拟人的产业发展现状

Docker installs redis-5.0.12. Detailed steps

60 个神级 VS Code 插件!!

Xinlou: Huawei's seven-year building journey of sports health

Shutter precautions for using typedef

YGG recent game partners list

These map operations in guava have reduced my code by 50%

Interviewer: you said you are proficient in redis. Have you seen the persistent configuration?

Information update on automatic control principle
随机推荐
字符串习题总结2
Opengauss kernel: simple query execution
The process from troubleshooting to problem solving: the browser suddenly failed to access the web page, error code: 0x80004005, and the final positioning: "when the computer turns on the hotspot, the
Creating files, recursively creating directories
磁盤的結構
Short video mall system, how does scroll view adapt to the remaining height of the page
first-order-model实现照片动起来(附工具代码) | 机器学习
Valueerror: cannot take a larger sample than population when 'replace=false‘
First order model realizes photo moving (with tool code) | machine learning
Seven principles of software design
Drag drag drag
学习笔记23--多传感器信息融合基础理论(上)
NiO, bio, AIO
The profound meaning of unlimited ecological development in Poka -- Multidimensional Interpretation of parallel chain
Collapse code using region
[200 opencv routines] 209 Color image segmentation in HSV color space
Structure du disque
如何提取网页中的日期?
Web攻击之CSRF和SSRF
A girl has been making hardware for ten years. 。。