Java Program to Implement ConcurrentLinkedQueue API
The ConcurrentLinkedQueue class in Java is a part of the Java Collection Framework. It belongs to java.util.concurrent package. It was introduced in JDK 1.5. It is used to implement Queue with the help of LinkedList concurrently. It is an unbounded thread-safe implementation of Queue which inserts elements at the tail of the Queue in a FIFO(first-in-first-out) fashion. It can be used when an unbounded Queue is shared among many threads.
To implement ConcurrentLinkedQueue API first we create a class “ConcurrentLinkedQueueImplmentation” and create all the methods of the queue in this class.
Implementation of the ConcurrentLinkedQueue API:
The elements of the ConcurrentLinkedQueue is: 10 20 30 40 50 Size of the concurrentLinkedQueue is: 5 The peek element of the concurrentLinkedQueue is: 10 The polled element of the concurrentLinkedQueue is: 10 Remove 30: true The concurrentLinkedQueue contains 40:true Size of the concurrentLinkedQueue is: 3
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.