Javatpoint Logo
Javatpoint Logo

Java LinkedTransferQueue take() Method

The take() method of Java LinkedTransferQueue class retrieves and removes the first element of the LinkedTransferQueue. This method also waits (if necessary) until an element becomes available.

Syntax:

Parameters:

NA

Specified By:

The take() method of LinkedTransferQueue class is specified by:

o take in interface BlockingQueue<E>.

Return Value:

The take() method returns the first element of this queue.

Throws:

InterruptedException: This exception will throw if interrupted while waiting.

Example 1

Test it Now

Output:

Elements are :
67
109
98
123
100
Queue = []

Example 2

Test it Now

Output:

Harry has passed.
Peter has passed.

Example 3

Test it Now

Output:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
	Unhandled exception type InterruptedException

	at tests.LinkedTransferQueueTakeExample3.main(LinkedTransferQueueTakeExample3.java:17)

Note: To resolve this error, either we should add exception to the method signature or should surround the take() method with try and catch.






Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials