Constructor in Java

Constructor in Java is a special method which is called automatically to initialize an object when the object is created. Need for a constructor When an object is created it is a very common requirement to initialize that object (provide values for its instance variables). To facilitate that a constructor…

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