1
JavaAdvanced#concurrency#java8
ReentrantLock (java.util.concurrent.locks) offers advanced features like tryLock with timeout, interruptible lock acquisition, and fairness policies, whereas synchronized is simpler but less flexible and always blocks indefinitely.
ReentrantLock lock = new ReentrantLock();
if (lock.tryLock(1, TimeUnit.SECONDS)) {
try { /* critical section */ } finally { lock.unlock(); }
}