From this I understand: "Since the calls to the lock () and unlock () methods are explicit, we can move them anywhere, setting any blocking area, from one line of code to an area that spans several methods"
So, what I understand from the above statement,
public class Test { Lock l = new ReentrantLock(); void myMethod1() { l.lock();
So, basically, I can call method1 and method2 sequentially and assume that the call is thread safe.
I am not sure if this is true, as stated above.
What if someone just calls method2 when I am already executing a pair of method1 / method2? Doesn't that complicate the situation?
I think that a lock must be obtained and released in the function itself before the control is returned from the function. Do I understand correctly?
java multithreading reentrantlock
S kr
source share