views:

107

answers:

3

If a thread holds a lock , what happens when the thread needs to enter another critical section controlled by the same lock?

+1  A: 

nothing: the system is able to determine which thread holds the lock to avoid a thread blocking itself.

Maurice Perry
+6  A: 

Intrinsic locks (synchronized) in Java are reentrant, thus the JVM will recognize that the current thread already holds this lock and it will proceed.

There are also explicit locks, that are reentrant.

If a lock is not reentrant, you could for instance not use recursive methods.

PartlyCloudy
A: 

If a thread holds a lock then it can enter any methods(synchronized or non synchronized), but if any other thread wants to call a method then the methods should be non synchronized or it should wait to acquire the lock if it tries to call a synchronized method.

GK