I'm new to Java Threads and synchronization.
Lets say I have:
public class MyClass(){
public synchronized void method1(){
//call method2();
}
public synchronized void method2(){};
}
What does it mean when I synchronize a method1()
on an instance object? So when a thread acquired the lock when trying to access the synchronized method1()
, does it prevent other threads to access another synchronized method2()
from that same object?
Lets say a thread acquires a lock when accessing method1(), but lets say that method1()
makes a call to method2()
which is also synchronized
. Can this be possible? I mean are there any rules that can prevent method1()
from calling method2()
?
Thanks in advance.