本文主要是介绍JSR Happens Before规则,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
JSR Happens Before规则
- Happen Before规则
Happen Before规则
- 程序顺序规则: 线程中的每个动作A都happens-before于该线程中的每一个动作B,其中,在程序中,所有的动作B都能出现在A之后。<
Each action in a thread happens before every subsequent action in that thread.
>
- 监视器锁规则: 对一个监视器锁的解锁 happens-before于每一个后续对同一监视器锁的加锁。<
An unlock on a monitor happens before every subsequent lock on that monitor.
>
- volatile变量规则: 对volatile域的写入操作happens-before于每一个后续对同一个域的读写操作。<
A write to a volatile field happens before every subsequent read of that volatile.
>
- 线程启动法则: 在一个线程里,对Thread.start的调用会happens-before于每个启动线程的动作。<
A call to start() on a thread happens before any actions in the started thread.
>
- 线程终结法则: 线程中的任何动作都happens-before于其他线程检测到这个线程已经终结、或者从Thread.join调用中成功返回,或Thread.isAlive返回false。<
All actions in a thread happen before any other thread successfully returns from a join() on that thread.
>
- 传递性: 如果A happens-before于B,且B happens-before于C,则A happens-before于C。<
If an action a happens before an action b, and b happens before an action c, then a happens before c.
>
- 中断法则: 一个线程调用另一个线程的interrupt方法 happens-before于被中断的线程发现中断。
- 终结法则: 一个对象的构造函数的结束happens-before于这个对象finalizer的开始。
JSR-133 中文版下载地址: https://download.csdn.net/download/summer_fish/12720774
程序验证: https://github.com/xiaxinyu/java-core/tree/master/src/main/java/com/xiaxinyu/java/thread
这篇关于JSR Happens Before规则的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!