The rule for a monitorexit (i.e., releasing synchronization) is that actions before the monitorexit must be performed before the monitor is released. However, there is no rule which says that actions after the monitorexit may not be done before the monitor is released.
高手能不能解释这段话的含义
监视程序退出的规则是,监视程序退出之前的Action必须在监视程序被释放之前被执行,
但是,也没有规则定下来说,监视程序退出之后的Action不可以在监视程序被释放之前被执行。
感觉好象绕口令,我再自己理解一下,看看是不是这个意思
如类Monitor
class Monitor {
//监视程序退出之前所要执行的Action
public void beforeExitMonitorAction() {}
//监视程序被释放的Action
public void releaseMonitor() {}
//监视程序退出之后所要执行的Action
public void afterExitMonitorAction () {}
}
假设实例化了这个类,如
Monitor m = new Monitor ();
然后再释放m,即让m退出
那么m中的这三个方法可能以如下的方式被调用
第一种 beforeExitMonitorAction --> releaseMonitor --> afterExitMonitorAction
第二种 beforeExitMonitorAction --> afterExitMonitorAction --> releaseMonitor
第三种 afterExitMonitorAction --> beforeExitMonitorAction --> releaseMonitor
感觉第三种形式不太可能
以上个人见解,欢迎指正