Given this example class:
class Example {
String str = "";
public synchronized boolean foo () { str = "foo"; }
public boolean bar() { str = "bar"; }
public synchronized boolean baz() { str = "baz"; }
}
From this post, it is clear that any thread can call the bar
method. Say thread T1
is in the middle of executing foo()
and thread T2
calls bar()
. Can bar()
reassign str
even though foo
has obtained a lock? What about the same question if baz
is called by T2
even though T2
is in the middle of executing foo
?