Java 中的哪些操作被认为是原子操作? [英] What operations in Java are considered atomic?

查看:27
本文介绍了Java 中的哪些操作被认为是原子操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java 中的哪些操作被认为是原子操作?

What operations in Java are considered atomic?

推荐答案

  • 除了 long 和 double 之外的所有原始类型赋值
  • 参考文献的所有分配
  • 所有可变变量的赋值
  • java.concurrent.Atomic* 类的所有操作
  • 也许还有更多.查看 jls.

    and maybe something more. Look at the jls.

    正如评论中所指出的,原子性并不意味着可见性.因此,虽然保证另一个线程不会看到部分写入的 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 上atomic 也是如此,虽然不能保证.另请参阅此功能请求.

    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 中的哪些操作被认为是原子操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆