为调用 wait 方法的线程获取内部锁的方法
Ways to acquire the intrinsic lock for the thread calling the wait method
从逻辑上讲,调用wait
方法的线程应该已经获取了wait
被调用对象的内在锁。
在 oracle 教程 here 中指出 "invoking wait
inside a synchronized method of the object is a simple way to acquire the intrinsic lock",这意味着至少可能有另一种方法来获取锁。
我的问题是,为了调用wait
,除了在synchronized 方法中调用wait
之外,还有其他方法来获取内部锁吗? ...它们是什么?
spring 需要注意的一些(密切相关的)其他人:
在 synchronized
块中:
synchronized (this) {
wait();
}
在非同步方法中,从同步方法内部调用:
synchronized void a() {
b();
}
void b() {
wait();
}
在非同步方法中,从同步块内部调用:
synchronized (this) {
b();
}
void b() {
wait();
}
从逻辑上讲,调用wait
方法的线程应该已经获取了wait
被调用对象的内在锁。
在 oracle 教程 here 中指出 "invoking wait
inside a synchronized method of the object is a simple way to acquire the intrinsic lock",这意味着至少可能有另一种方法来获取锁。
我的问题是,为了调用wait
,除了在synchronized 方法中调用wait
之外,还有其他方法来获取内部锁吗? ...它们是什么?
spring 需要注意的一些(密切相关的)其他人:
在
synchronized
块中:synchronized (this) { wait(); }
在非同步方法中,从同步方法内部调用:
synchronized void a() { b(); } void b() { wait(); }
在非同步方法中,从同步块内部调用:
synchronized (this) { b(); } void b() { wait(); }