现在,我不确定这是否是一个愚蠢的问题,如果是,请多多包涵。
对象上的锁是“递归的”吗,即如果两个对象在其字段中引用了第三个对象,并且一个线程正在两者之一上运行同步方法,那么任何其他线程都可以访问第三个对象吗?
// a and b are some objects that implement Runnable
// they both reference the same third object
a.ref = c;
b.ref = c;
// a is run in a thread and processes some data in a loop for a long time
// the method the loop belongs to is declared synchronized
threadA = new Thread(a);
threadA.start();
a.someSyncedMethod(); // this would block ...
b.ref.someOtherSyncedMethod(); // ... but would this?
a.ref.someOtherSyncedMethod(); // ... and how about this?