Introduction Locking refers to a mechanism taken for granted in a relational database to prevent any modification to the data between the time the data are read and the time the data are used. There are mainly two types of locking strategy available – optimistic and pessimistic

Posted in Hibernate

Hibernate Locking

A ReadWriteLock interface in Java is more sophisticated than the Lock interface. Imagine you have an application that reads from and writes to some resources, but reading frequency is much more higher than writing frequency. Two or more threads reading the same resource do not cause any problem for each other, i.e., multiple threads reading…

Posted in Java

ReadWriteLock in Java

A Reentrant lock is an implementation of java.util.concurrent.Lock interface with the same basic behavior and semantics as the implicit monitor lock accessed using synchronized methods and statements, but with extended capabilities. Lock is acquired by lock() method and held by Thread until a call to unlock() method. ReentrantLock provides same visibility and ordering guarantee, provided…

Posted in Java

ReentrantLock in Java

Introduction You may be already aware of basic concepts around thread synchronization and various mechanisms using synchronized keyword. A lock interface is a thread synchronization aid like synchronized block except lock can be used in a more sophisticated way than Java’s synchronized blocks. A lock is a tool for controlling access to a shared resource…

Posted in Java

Lock in Java