We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No description provided.
The text was updated successfully, but these errors were encountered:
一. 我们经常会使用i++操作,大家都知道这个并不是线程安全的,这时通常会使用synchroized关键字来处理并发操作,在并发量不大的情况使用synchroized性能并不是特别高。在jdk1.6以前synchroized是重量级锁,无论有没有资源竞争都会对变量加锁,在jdk1.6之后引入了偏向锁和轻量级锁,效率才有了很大的提升。atomic类使用了cas的思想,只有真正资源竞争的时候才会有资源消耗,而且atomic是通过底层硬件指令集实现的,所以并发量不大的情况下性能更高。 二. 主要原理就是CAS(比较和交换), 涉及到三个值(V, O, N), V是内存中真正的值,O是加载到线程中的预期值,N是计算后的目标结果值,当计算出目标结果值时比较V和O是否相等,不相等代表V被其他线程改写过,那么将V重新赋值给O,然后重新计算目标值,再次重复上述步骤,这个称为自旋操作。 缺点:
Sorry, something went wrong.
No branches or pull requests
No description provided.
The text was updated successfully, but these errors were encountered: