Difference Between Synchronized And ReentrantLock in Java

The traditional way of acquiring a mutual exclusion lock in Java is to use synchronized keyword but Java 5 added new lock implementations like ReentrantLock and ReentrantReadWriteLock which provide extended locking operations capabilities. In this post we’ll see the difference between synchronized and ReentrantLock in Java. ReentrantLock Vs synchronized in…

Continue reading

ReentrantReadWriteLock in Java

In this post we’ll see the usage of java.util.concurrent.locks.ReadWriteLock interface and its implementing class ReentrantReadWriteLock in Java with examples. ReadWriteLock in Java Concurrency ReadWriteLock as the name itself suggests has a pair of associated locks- One for read-only operations One for writing operations The usage of read lock and write…

Continue reading

ReentrantLock in Java

ReentrantLock in Java is part of java.util.concurrent.locks package with in the Java concurrency API added in Java 5 which also has other classes like ConcurrentHashMap, CountDownLatch. ReentrantLock class in Java implements java.util.concurrent.locks.Lock interface and provide many locking operations. ReentrantLock in Java Concurrency The traditional way of acquiring a mutual exclusion…

Continue reading

Phaser in Java

Many synchronization aid were added as the part of java.util.concurrent package in Java 5 like Semaphore, Exchanger. One more synchronization aid added as part of Java concurrency is Phaser which was added in Java 7. Phaser in Java concurrency Phaser in Java is also a synchronization barrier like CountDownLatch and…

Continue reading

Exchanger in Java

Many synchronization aid were added as the part of java.util.concurrent package in Java 5 like CyclicBarrier, Semaphore. One more synchronization aid added as part of Java concurrency is Exchanger. In this post we’ll see what is Exchanger in Java, how does it work and an example of Exchanger. Exchanger in…

Continue reading

CyclicBarrier in Java

The java.util.concurrent package provides many synchronizers utilities that cover the use cases where several thread communicate with each other and some sort of synchronizer is needed to regulate that interaction among the threads. CyclicBarrier in Java is one such synchronization aid that is useful when you want threads to wait…

Continue reading

CopyOnWriteArraySet in Java With Examples

CopyOnWriteArraySet in Java extends the AbstractSet which in turn implements the Set interface and is part of java.util.concurrent package. How CopyOnWriteArraySet differs from other Set implementations in Java Collections framework is that it is thread-safe. CopyOnWriteArraySet internal implementation in Java CopyOnWriteArraySet internally uses CopyOnWriteArrayList for all of its operations and…

Continue reading