O'Reilly logo

Java 9 Concurrency Cookbook - Second Edition by Javier Fernández González

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Monitoring a stream

A stream in Java is a sequence of elements that could be processed (mapped, filtered, transformed, reduced, and collected) either parallelly or sequentially in a pipeline of declarative operations using lambda expressions. It was introduced in Java 8 to change the way one can process enormous sets of data in a functional way, with lambda expressions instead of the traditional imperative way.

The Stream interface doesn't provide a lot of methods as other concurrency classes to monitor its status. Only the peek() method allows you to write log information about the elements that are being processed. In this recipe, you will learn how to use this method to write information about a stream.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required