Monthly Archive: March 2018

Implement a Reentrant Lock in Java 0

Implement a Reentrant Lock in Java

Let’s try to implement our own custom Lock. For sake of simplicity we will not implement interruptible, non-interruptible, and timed forms of the lock /* * For sake of simplicity – assume custom lock...

How is Java Lock better than Synchronization 0

How is Java Lock better than Synchronization

Here are few benefits of using Java’s Lock API over Synchronization 1.Java Lock API provides more visibility and options for locking, unlike synchronized where a thread might end up waiting indefinitely for the lock,...

When should we use Volatile variables 0

When should we use Volatile variables

In general each thread has its own copy of variable, such that one thread is not concerned with the value of same variable in the other thread. But sometime this may not be the...