I'm a newbie to threads and specifically the synchronized
key word.
I understand that a thread's state changes to BLOCKED
if it tried to access a synchronized block where another thread already owns the lock.
For reference:
synchronized (objA){
objA.methodA();
}
//some code
objA.methodB();
My question is whether another thread can alter the object objA
through another independent method (methodB()
in this example). Or does owning the lock mean that no other thread can access/alter objA
in any way ie whether or not the alteration code is within the synchronized block?