SynchronousQueue is a special blocking queue with no internal capacity. It helps in exchange data or information between threads in a thread-safe manner.
SynchronousQueue has only 2 supported operations:
Both of these are blocking method which means when we want to add a piece of information or data in the queue, we call the put() method but this method will remain blocked or it will wait until some other thread calls take() method and allows the thread to take the data or information.
There are two types of constructors of SynchronousQueue which is based on two different access policy:
1. SynchronousQueue(): In this, if multiple threads are waiting then these threads are granted access randomly or unspecified manner, this is called no fair policy.
2. SynchronousQueue(boolean fair): In this, if multiple threads are waiting then these threads are granted access in FIFO(first in first out) manner.
1 added to synchronous queue. 1 removed from synchronous queue.
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.