LinkedTransferQueue hasWaitingConsumer() method in Java Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The Java.util.concurrent.LinkedTransferQueue.hasWaitingConsumer() method always returns true if there is at least one consumer in the queue waiting to receive an element via BlockingQueue.take() or timed poll. The returned value represents a momentary state of affairs. Syntax public boolean hasWaitingConsumer() Parameters: It does not take in any parameter. Return Value: This method returns a boolean value which is true if at least one consumer is present in the queue. Below are a few examples to illustrate the LinkedTransferQueue.hasWaitingConsumer() method: Example 1: Java // Java code to demonstrate // hasWaitingConsumer() method import java.util.concurrent.LinkedTransferQueue; class GFG { public static void main(String args[]) { LinkedTransferQueue<String> LTQ = new LinkedTransferQueue<String>(); LTQ.add("Geeks"); LTQ.add("For"); LTQ.add("Geeks"); LTQ.add("GeeksForGeeks"); System.out.println(LTQ.hasWaitingConsumer()); } } Output: false Example 2: Java // Java code to demonstrate // hasWaitingConsumer() method import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.LinkedTransferQueue; public class GFG { LinkedTransferQueue<Integer> LTQ = new LinkedTransferQueue<>(); class LTQProducer implements Runnable { @Override public void run() { for (int i = 0; i < 3; i++) { try { System.out.println("Producer is" + " waiting to transfer"); LTQ.transfer(i); System.out.println("Producer transferred" + " element: " + i); System.out.println("Is there any consumer" + " still waiting to" + " receive an element" + " after transfer -> " + LTQ.hasWaitingConsumer()); } catch (InterruptedException e) { e.printStackTrace(); } } } } class LTQConsumer implements Runnable { int id; LTQConsumer(int id) { this.id = id; } @Override public void run() { try { System.out.println("Consumer " + id + " is waiting to " + "take an element."); System.out.println("Is there any consumer" + " still waiting to" + " receive an element" + " after transfer -> " + LTQ.hasWaitingConsumer()); Integer s = LTQ.take(); System.out.println("Consumer " + id + " received Element: " + s); } catch (InterruptedException e) { System.out.println(e); } } } // Driver code public static void main(String[] args) throws InterruptedException { GFG ob = new GFG(); ExecutorService exService = Executors.newFixedThreadPool(3); LTQProducer p = ob.new LTQProducer(); LTQConsumer c1 = ob.new LTQConsumer(0); LTQConsumer c2 = ob.new LTQConsumer(1); exService.execute(p); exService.execute(c1); exService.execute(c2); exService.shutdown(); } } Output: Producer is waiting to transfer Consumer 0 is waiting to take an element. Is there any consumer waiting to take an element -> false Consumer 1 is waiting to take an element. Is there any consumer waiting to take an element -> false Consumer 0 received Element: 0 Producer transferred element: 0 Is there any consumer still waiting to receive an element after transfer -> true Producer is waiting to transfer Producer transferred element: 1 Consumer 1 received Element: 1 Is there any consumer still waiting to receive an element after transfer -> false Producer is waiting to transfer Comment More infoAdvertise with us Next Article LinkedTransferQueue add() method in Java P psil123 Follow Improve Article Tags : Java Java-Collections Java - util package Java-Functions Java-LinkedTransferQueue +1 More Practice Tags : JavaJava-Collections Similar Reads LinkedTransferQueue getWaitingConsumerCount() method in Java with Examples The java.util.concurrent.LinkedTransferQueue.getWaitingConsumerCount() method returns the number of consumers waiting to receive elements via take() or timed poll, from the LinkedTransferQueue(LTQ). Consumers here will read elements from the LTQ. Producers will add elements to the LTQ. This method w 3 min read LinkedTransferQueue drainTo() method in Java drainTo(Collection c) The drainTo(Collection c) method of java.util.concurrent.LinkedTransferQueue Class is an in-built function in Java which removes all the elements present in this queue and adds them to the provided collection. This is a more efficient way than repeatedly polling this queue. The 5 min read LinkedTransferQueue contains() method in Java The contains() method of java.util.concurrent.LinkedTransferQueue is an in-built function in Java which returns a true boolean value if the specified element is present in this queue otherwise it returns false. Syntax: LinkedTransferQueue.contains(Object o) Parameters: The function accepts a single 2 min read LinkedTransferQueue add() method in Java The add() method of java.util.concurrent.LinkedTransferQueue is an in-built function in Java which is used to insert an element in this queue. Syntax: LinkedTransferQueue.add(E e) Parameters: The function accepts a single parameter e i.e. the element to be inserted. Return Value: The function return 2 min read LinkedTransferQueue isEmpty() method in Java The isEmpty() method of java.util.concurrent.LinkedTransferQueue is an in-built function in Java which checks if this queue is empty or not. Syntax: LinkedTransferQueue.isEmpty() Return Value: The function returns a boolean value. It returns true if the LinkedTransferQueue is empty and returns false 1 min read LinkedTransferQueue put() method in Java The java.util.concurrent.LinkedTransferQueue.put() method is an in-built function in Java which is used to insert an element in this queue. It waits till the space becomes available if queue is full. Syntax: LinkedTransferQueue.put(E e) Parameters: The function accepts a single parameter e i.e. the 2 min read Like