ConcurrentHashMap CAS
时间: 2023-10-14 15:04:22 浏览: 99
ConcurrentHashMap使用了CAS(Compare and Swap)操作来实现并发安全和高效的并发。CAS是一种无锁算法,它可以在多线程环境下实现对共享变量的原子操作。具体来说,当多个线程对ConcurrentHashMap进行并发操作时,每个线程会先通过CAS操作来比较当前值和期望值是否相等,如果相等则进行更新操作,否则重新尝试。这样可以避免了使用锁来同步访问共享变量的开销,提高了并发性能。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [day09(二)-ConcurrentHashMap原理-CAS](https://blog.csdn.net/ym15229994318ym/article/details/105473777)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *3* [什么是ConcurrentHashMap【CAS+Volatile/Synchronizaed】?](https://blog.csdn.net/m0_64210833/article/details/126294540)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文