本文介绍了Java中的哪些操作被认为是原子的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Java中的哪些操作被认为是原子的?
What operations in Java are considered atomic?
推荐答案
- 原始类型的所有赋值除外long和double
- 所有引用分配
- 所有volatile变量赋值
- java的所有操作。 concurrent.Atomic * classes
- all assignments of primitive types except for long and double
- all assignments of references
- all assignments of volatile variables
- all operations of java.concurrent.Atomic* classes
还可能更多。请查看。
如评论中所述,原子性并不意味着可见性。因此,虽然保证另一个线程不会看到部分写入 int
,但它可能永远不会看到新值。
As noted in the comments, atomicity does not imply visibility. So while another thread is guaranteed not to see a partially written int
, it may never see the new value.
long和double上的操作在常见的64位CPU上。
The operations on long and double are on common 64 bit CPUs atomic as well, although there's no guarantee. See also this feature request.
这篇关于Java中的哪些操作被认为是原子的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!