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 differs 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

Initializer Block in Java

When you create an instance of a class, constructor is called to initialize the instance variables. An alternative to using a constructor to initialize instance variable is to use initializer block in Java. Initializer block is always executed when an instance of the class is created. General form of Initializer…

Continue reading