34

CAS都不了解,你还怎么看J.U.C-Java_老男孩

 4 years ago
source link: https://blog.51cto.com/14230003/2464229
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
前言说到CAS(CompareAndSwap),不得不先说一说悲观锁和乐观锁,因为CAS是乐观锁思想的一种实现。悲观锁:总是很悲观的认为,每次拿数据都会有其他线程并发执行,所以每次都会进行加锁,用完之后释放锁,其他的线程才能拿到锁,进而拿到资源进行操作。java中的synchronized和ReentrantLock等独占锁就是悲观锁思想的实现。乐观锁:总是很乐观认为,自己拿到数据操作的时候,没有

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK