Let's say I have a ReentrantLock
,
ReentrantLock foo = new ReentrantLock();
and a method bar
that uses the lock,
public void bar()
{
foo.lock();
try
{
methodOne();
}
finally
{
foo.unlock();
}
}
and methodOne
calls a method methodTwo
that also uses the lock,
public void methodTwo()
{
foo.lock();
try
{
// do something
}
finally
{
foo.unlock();
}
}
is it better to release the lock in bar
before I call methodOne
? In general, is it good practice to release the lock before calling another method?