![]() |
VOOZH | about |
The put(E e) method of LinkedBlockingQueue inserts element passed as parameter to method at the tail of this LinkedBlockingQueue, if queue is not full. If the queue is full, then this method will wait for space to become available and after space is available, it inserts the element to LinkedBlockingQueue.
Syntax:
public void put(E e) throws InterruptedException
Parameter: This method takes a mandatory parameter e which is the element to be inserted in LinkedBlockingQueue.
Return Value: The method does not return anything.
Exception: This method throws following exceptions:
Below programs illustrates put(E e) method of LinkedBlockingQueue class:
Program 1: Prints Element of LinkedBlockingQueue after adding new names to queue using put() method.
Items in Queue are [Karan, Suraj, Harsh, Rahul]
Program 2: Add Employee object using put method in LinkedBlockingQueue
Details of Employees: Employee [name=Ranjeet, position=Tester, salary=29000, Age=27] Employee [name=Sanjeet, position=Manager, salary=98000, Age=34] Employee [name=Karan, position=Analyst, salary=44000, Age=30]
Program 3: To show NullPointerException thrown by put() method
Exception: java.lang.NullPointerException
Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/LinkedBlockingQueue.html#put-E-