I am trying to learn basic concepts of Java 8 Concurrent Programming and can not understand the Unlock with return in a demo snippet here : http://www.javatips.net/api/thinking-java-master/src/main/java/ch21concurrent/examples/ConditionBoundedBuffer.java
// BLOCKS-UNTIL: notEmpty
public T take() throws InterruptedException {
lock.lock();
try {
while (count == 0)
notEmpty.await();
T x = items[head];
items[head] = null;
if (++head == items.length)
head = 0;
--count;
notFull.signal();
return x; // <<< RETURN without UNLOCK ? <<<
} finally {
lock.unlock();
}
}
I read about the motivation try / finally for a secure Unlock, but what about the 'return x' here, is the monitor proc. then unlocked with this return ?