DelayQueue in Java

DelayQueue in Java is an implementation of BlockingQueue interface and is part of java.util.concurrent package. DelayQueue in Java is an unbounded queue that’s where it differ from ArrayBlockingQueue which is a bounded queue. Delayed interface DelayQueue can store elements only of type Delayed. There is an interface Delayed in Java…

Continue reading

SynchronousQueue in Java

SynchronousQueue in Java is an implementation of BlockingQueue interface and is part of java.util.concurrent package. SynchronousQueue in Java is different from other BlockingQueue implementations like ArrayBlockingQueue and PriorityBlockingQueue because a synchronous queue does not have any internal capacity, not even a capacity of one. So, each insert operation in SynchronousQueue…

Continue reading

PriorityBlockingQueue in Java

PriorityBlockingQueue in Java is an implementation of BlockingQueue interface and is part of java.util.concurrent package. PriorityBlockingQueue is an unbounded queue PriorityBlockingQueue is logically unbounded that’s how is differ from ArrayBlockingQueue which is a bounded queue and LinkedBlockingQueue which is optionally-bounded. PriorityBlockingQueue though unbounded is created with an initial capacity which…

Continue reading

LinkedBlockingQueue in Java

LinkedBlockingQueue in Java is an implementation of BlockingQueue interface and is part of java.util.concurrent package. LinkedBlockingQueue has the features of both ArrayBlockingQueue and DelayQueue. ArrayBlockingQueue is a bounded blocking queue where as DelayQueue is an unbounded blocking queue. LinkedBlockingQueue sits in the middle as it is an optionally-bounded blocking queue…

Continue reading

ArrayBlockingQueue in Java

ArrayBlockingQueue in Java is an implementation of BlockingQueue interface and is part of java.util.concurrent package. ArrayBlockingQueue is a bounded blocking queue which internally uses an array to store elements. This queue orders elements FIFO (first-in-first-out). The head of the queue is the element that has been on the queue the…

Continue reading

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