Blocking Queues
A queue is a data structure with two fundamental operations: to add an element to the tail of the queue and to remove an element from the head. That is, the queue manages the data in a first-in/first-out discipline. A blocking queue causes a thread to block when you try to add an element when the queue is currently full or to remove an element when the queue is empty. Blocking queues are a useful tool for coordinating the work of multiple threads. Worker threads can periodically deposit intermediate results in a blocking queue. Other worker threads remove the intermediate results and modify them further. The queue automatically balances the workload. If the first set of threads runs slower than the second, the second set blocks ...
Get Core Java™ 2 Volume II - Advanced Features, Seventh Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.