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 thesynchronized method1()
, does it prevent other threads to access anothersynchronized method2()
from that same object?Lets say a thread acquires a lock when accessing method1(), but lets say that
method1()
makes a call tomethod2()
which is alsosynchronized
. Can this be possible? I mean are there any rules that can preventmethod1()
from callingmethod2()
?
Thanks in advance.