From the course: Learning Java Enterprise Edition

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Java 8 and Java EE 7: Parallel streams

Java 8 and Java EE 7: Parallel streams - Java EE Tutorial

From the course: Learning Java Enterprise Edition

Start my 1-month free trial

Java 8 and Java EE 7: Parallel streams

- [Narrator] Let's have a look at another example where we can take advantage of Java 8 features. We are going to go back to the real time CargoTracking service class that we visited in the web sockets video. Remember that when a client connects to the web socket endpoint a session is created and stored in a collection called sessions. And when a cargo event occurs, each one of the sessions in the collection is notified. Each client is notified in series, one after another. And as you can imagine, if there are thousands or hundreds of thousands of sessions in the collection it might take some time to iterate over all of those sessions. To solve this we can use parallel streams. Please take advantage of the new parallel processing power in Java 8. Let's see this in action. The collection API has a parallel stream method, so all of the collection implementations will inherit this method. So let's get started. So now we have a parallel stream. Now we need a forEach method in which we put…

Contents