Java Locks

Java Concurrency

Java Semaphore vs ReentrantLock

Learn what a Semaphore and a Reentrant Lock are along with practical examples. We will also explore some of the main differences between the two and the use cases where we can use these while working in a multithreaded application. 1. What is a Semaphore? A Semaphore is a Thread synchronization construct that acts as …

Difference between lock and monitor – Java Concurrency

You may have faced this question in your interview that what is the difference between lock and a monitor? Well, to answer this question you must have good amount of understanding of how java multi-threading works under the hood. Short answer, locks provide necessary support for implementing monitors. Long answer …

Java Locks (with Examples)

Java provides another mechanism for the synchronization of blocks of code based on the Lock interface and classes that implement it (such as ReentrantLock). In this tutorial, we will see a basic usage of Lock interface to solve printer queue problem. 1. Lock Interface A java.util.concurrent.locks.Lock is a thread synchronization …

Object level lock vs Class level lock in Java

In Java, a synchronized block of code can only be executed by one thread at a time. Also, java supports multiple threads to be executed concurrently. This may cause two or more threads to access the same fields or objects at same time. Synchronization is the process which keeps all …

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.