Q:

Modifying instance variables from nonsynchronized/synchronized context

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?

A:

You need to make str volatile first for threads to be a able to see each others changes else they will only see local copy.
Second issue is of one thread is in middle of modifying it and another thread reads it then you will get inconsistent state. So if a variable is shared across threads then make it volatile and any modification should be made in a synchronized block/method.
So to answer your questiond : Can bar() reassign str even though foo has obtained a lock? -> Yes.
Same applies for T2. But you will not able to gurantee a consistent state unless you synchronize bar.

