您的位置:首页 > 健康 > 养生 > 完美解释 Java 中的 内存模型 JMM 规则

完美解释 Java 中的 内存模型 JMM 规则

2024/10/7 4:28:11 来源:https://blog.csdn.net/go9898/article/details/140718898  浏览:    关键词:完美解释 Java 中的 内存模型 JMM 规则
Happens-before的原则

英文:

  • Each action in a thread happens-before every action in that thread that comes later in the program’s order.
  • An unlock on a monitor happens-before every subsequent lock on that same monitor.
  • A write to a volatile field happens-before every subsequent read of that same volatile.
  • A call to start method on a thread happens-before any actions in the started thread.
  • All actions in a thread happens-before any other thread successfully returns from a join method on that thread.

翻译:

  • 程序顺序规则:一个线程中, 每一个操作happens-before 于该线程中的任意后续操作。
  • 监视器锁规则:对监视器锁的一个解锁操作,happens-before 于随后对同一个监视器锁的加锁操作。
  • volatile变量规则:对一个volatile域的写操作,happens-before 于任意后面对这个volatile域的读操作。
  • 传递性规则:如果A happens-before B,且B happens-before C,那么A happens-before C。
  • 线程启动规则:Thread.start()的调用会happens-before于启动线程里面的动作。
  • 线程顺序规则:Thread中的所有动作都happens-before于其他线程从Thread.join中成功返回。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com