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.
Getting ready
The example of this recipe has been implemented using the Eclipse IDE. If you use Eclipse or a different IDE, such as NetBeans, open it and create a new Java project.
How to do it...
Follow these steps to implement the example:
- Create a class named
Main
with amain()
method. Declare...