同一个线程synchronized方法调用synchronized方法
一个线程里面有两个synchronized方法a(),b().
假如在a()里面调用b(),会发生什么情况?这样
public synchronized void a(){
...
b()
...
}
public synchronized void b(){
...
}
a()会被hang住吗?
一个线程里面有两个synchronized方法a(),b().
假如在a()里面调用b(),会发生什么情况?这样
public synchronized void a(){
...
b()
...
}
public synchronized void b(){
...
}
a()会被hang住吗?
评论功能维护中,当前仅展示历史评论。
A synchronized area (by which we mean a synchronized block or method) does not blindly grab the lock when it enters the code section and free the lock when it exits. If the current thread already owns the object lock, there is no reason to wait for the lock to be freed or even to grab the lock. Instead the code in the synchronized area merely executes. Furthermore, the system is smart enough not to free the lock if it did not initially grab it upon entering the synchronized area.