Blog

Your dream job? Lets Git IT.
Interactive technical interview preparation platform designed for modern developers.

XGitHub

Platform

  • Categories

Resources

  • Blog
  • About the app
  • FAQ
  • Feedback

Legal

  • Privacy Policy
  • Terms of Service

© 2025 LetsGit.IT. All rights reserved.

LetsGit.IT/Categories/Java
Javahard

`synchronized` vs `ReentrantLock` - when would you choose one?

Tags
#concurrency#locks#synchronized#reentrantlock
Back to categoryPractice quiz

Answer

`synchronized` is simpler and uses JVM monitors, giving mutual exclusion and a clear happens-before relationship. `ReentrantLock` is more flexible: `tryLock()`, timeouts, fairness options, and multiple `Condition`s—but you must always `unlock()` in `finally`.

Related questions

Java
HashMap vs ConcurrentHashMap: when should you use each?
#java#collections#concurrency
Java
`synchronized` vs `ReentrantLock`: what are the differences?
#java#concurrency#locks
Java
Parallel streams: when can they help and what are common pitfalls?
#java#streams#parallel
Java
What does `ThreadLocal` do and what is a common pitfall?
#threadlocal#concurrency#thread-pool
Java
Java Memory Model: what does “happens-before” mean (in simple terms)?
#jmm#happens-before#concurrency
Java
Why is `ArrayList` not thread-safe, and how can you make list access safe?
#concurrency#arraylist#thread-safety