I have two classes
public class A {
private byte[] buf;
public synchronized void foo() {
// does something with buf
}
public class B {
public synchronized void bar() {
// also does something with buf
}
}
}
As far as I know, method bar()
is synchronized on an instance of class B
. How can I synchronize it on the object of class A
in order to protect the buf
?