当前位置:网站首页>Concurrent operation -- the difference between reentrantlock and synchronized
Concurrent operation -- the difference between reentrantlock and synchronized
2022-06-09 03:25:00 【RobertTeacher】
Concurrent operations
Concurrent operation ——ReenTrantLock and synchronized The difference between .
Concurrent operation ——ReenTrantLock and synchronized The difference between
Synchronized and ReenTrantLock The differences and use scenarios
The problem of locking multiple threads in high concurrency environment .
One 、synchronized and ReenTrantLock The difference between ?
1、synchronized
Pessimistic locking , Reentrant lock , Not fair lock , Unable to get the state of the lock , It will cause other threads to block ,java Built in keywords , Implicit locking , Simple operation but not flexible enough .


2、ReenTrantLock
Pessimistic locking , Reentrant lock , It can be fair lock or unfair lock ( When creating, pass in parameters true Create fair locks ,false and null It's all unfair locks ), Manual lock and unlock required , The unlocking operation should be placed in finally In the code , Make sure the thread releases the lock correctly , The difference at the bottom is AQS Of state and FIFO Queue to control locking .
Two 、synchronized and ReenTrantLock Usage scenarios of
1、synchronized
In general, the use of concurrency scenarios is sufficient , Can be placed on methods that are executed recursively , And don't worry about whether the thread can release the lock correctly in the end .
2、ReenTrantLock
When used in complex scenarios, the number of times to repeatedly acquire a lock must be the same as the number of times to repeatedly release a lock during reentry , Otherwise, other threads may not be able to obtain the lock .
summary
The main difference is ReenTrantLock You can control the lock and view the lock status more flexibly ,synchronized Unable to determine whether to acquire the lock state .
边栏推荐
- FPGA first try
- opencv学习笔记一
- Neural network learning (IV) -- a simple summary of the knowledge of each layer of neural network
- Multi scale aligned distillation for low resolution detection
- Leetcode 871. Minimum refuelling times priority queue
- Cw2015 alarm function
- This book has won the 2022 Beijing college entrance examination composition!
- Ccf-csp 202203-3 computing resource scheduler 80 points
- 并发操作之——ReentrantReadWriteLock
- 一文搞懂Cookie+Session,Redis+Token,JWT三者的区别
猜你喜欢

Leetcode 238. Product of arrays other than itself

85.(leaflet之家)leaflet军事标绘-直线箭头绘制

Redis6学习笔记-第一章-Redis的介绍与环境搭建

现在VB6.0已经和SQL连接了,但是使用查询功能时无法做到任意条件查询,网上的情况和我的也不太相符,请问该如何实现呢?

Spark - logging simple to use

Ccf-csp 202006-3 markdown renderer 60

About JS console Log() is a problem caused by synchronous or asynchronous

ERP starts from internal integration

What is the network transformer for? (Ethernet network LAN LAN communication isolation filter) production plant / product schematic diagram / common products / price influencing factors

ERP overview
随机推荐
2022年短期理财产品排行榜
故障分析 | 大量短时进程导致 cpu 负载过高案例一则
Ccf-csp 202203-1 uninitialized warning
Two Merged Sequences(CF 1144 G)(将序列拆分成升序序列和降序序列两部分)-DP
Ccf-csp 201903-2 24:00
Tamidog information | Maersk completed another large-scale enterprise acquisition
关于回调的一些思考
[launch] modify the app theme according to the wallpaper. It really comes
神经网络学习(五)----常见的网络结构对比
Ccf-csp 202203-3 computing resource scheduler 80 points
Ccf-csp 201909-4 recommended system 100 points
How does the rtsp/onvif protocol video platform easynvr configure the playback duration of a user's video stream?
Electron desktop development (process)
The difference between single chip and chip
Understand the difference between cookie+session, redis+token and JWT
Do you know the specifications of e-commerce background permission settings!
ERP从内部集成起步开篇
InfoQ geek media's 15th anniversary solicitation | one minute Automated Deployment Based on ECs [elastic ECS]
No cached version available for offline mode
[detailed explanation of kubernetes 12] - Security Certification