Java · OOP, JVM and backend craft

How does synchronized compare with explicit locks?

HardsynchronizedreentrantlocklockingUpdated Oct 2026
Quiz this track

Short answer

synchronized uses the intrinsic monitor and is simple and automatically released. ReentrantLock offers explicit locking with tryLock, interruptibility, fairness and multiple conditions.

A synchronized method or block acquires the object's monitor. The JVM releases it automatically when the block exits, including on exception. ReentrantLock is a class in java.util.concurrent.locks that requires an explicit unlock in a finally block.

java
private final ReentrantLock lock = new ReentrantLock();

public void transfer(Account from, Account to, long amount) {
    lock.lock();
    try {
        from.withdraw(amount);
        to.deposit(amount);
    } finally {
        lock.unlock();
    }
}
The finally block is mandatory. Without it, an exception leaves the lock held.

What ReentrantLock adds

  • tryLock with an optional timeout instead of blocking forever
  • lockInterruptibly so a thread can respond to cancellation
  • An optional fairness policy, which reduces starvation but lowers throughput
  • Multiple Condition objects for separate wait sets
  • ReentrantReadWriteLock for reader-writer separation

Prefer synchronized for simple mutual exclusion because it is harder to misuse. Reach for ReentrantLock when you need non-blocking acquisition, timeouts, interruptibility or multiple conditions. Both are reentrant: the same thread can acquire the lock again.

Historically, synchronized pinned virtual threads to carrier threads. JEP 491 in Java 24 removed that limitation, so the older advice to replace synchronized purely for virtual threads is no longer current.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1Why must unlock be called in a finally block?
  2. 2When is tryLock useful?
  3. 3What does lock fairness cost?
  4. 4What is a Condition used for?

Say it in the interview

synchronized is the intrinsic monitor: simple, reentrant and automatically released. ReentrantLock costs more ceremony because I must unlock in a finally block, but it adds tryLock, timeouts, interruptible acquisition, fairness and multiple conditions. I default to synchronized for straightforward mutual exclusion and use ReentrantLock when I need those advanced controls. Virtual-thread pinning used to be a reason to prefer locks, but Java 24 removed that limitation.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Java mock interview and get scored feedback on depth, clarity and confidence.