How do you check if a Thread holds a lock or not?

Java provides Thread.holdsLock(Object obj), a static method that returns true if the currently executing thread holds the intrinsic (monitor) lock on the given object, which is mainly useful for debugging, assertions, and validating locking assumptions.

Key Points

Example

A private helper method that assumes the caller already holds a lock on the accounts object can start with assert Thread.holdsLock(accounts) : "must hold accounts lock", catching a programming mistake early during development and testing.

private void updateBalanceInternal(Account acc, BigDecimal amount) {
    assert Thread.holdsLock(acc) : "caller must hold lock on account";
    acc.setBalance(acc.getBalance().add(amount));
}

Interview Tip

A concise interview answer is

For intrinsic locks, Thread.holdsLock(obj) tells the current thread whether it holds the monitor on that object, which is handy in assertions to validate locking assumptions during development. For ReentrantLock, the equivalent is lock.isHeldByCurrentThread(). Neither lets you inspect another thread's locks directly — for that you'd reach for a thread dump or ThreadMXBean.

Last updated: 16 July 2026

Previous question: How do you handle thread interruption in Java?

Next question: What are use cases of ThreadLocal variables in Java?

More Concurrency and Multithreading interview questions

All Concurrency and Multithreading questions