I have some confusion regarding thread Synchronization. Consider i have two thread Thread1 and Thread2 and two method synchronized foo1() and foo2(). foo1() is synchronized method and foo2() is not, in foo1 internally there is a statement which calls foo2() and if Thread1 calls foo1() and in that it is working in foo2() method, at the same time Thread2 want to access foo2() method directly which is not synchronized.
So my question is
will Thread2 get access of Foo2()? or it will wait for Thread1 to complete its task?
It is the object, not the method which is locked. This means you can have the two threads in foo1() if they are accessing different objects. If they are accessing the same object, the same lock will prevent concurrent access regardless of what is called first or what calls it.
BTW: foo1() can call itself as it already has the lock.