From the course: Java SE 21 Developer (1Z0-830) Cert Prep

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Concurrent queues and collections

Concurrent queues and collections - Java Tutorial

From the course: Java SE 21 Developer (1Z0-830) Cert Prep

Concurrent queues and collections

- Now, let's dive into concurrent queues and collections. The concurrent APIs provide a specialization of subclass, if you like, of the Queue interface, which is the BlockingQueue. The structure will be thread-safe, and inserting an item happens-before removal of that item, potentially in another thread. If the queue is full, the put method will block until space is available. And if the queue is empty, the take method will block until new data is available. Also, the order of insertion to removal is maintained. There will be no duplications or data loss, even in the face of multiple inserting and removing threads concurrently. So, put one item in. You'll get that one item out once, no matter how many conflicts there are for putting things in or for taking things out. So here's the API documentation page for the BlockingQueue. Obviously, it's generic, so you can decide what types go into it. It is, in itself, a…

Contents