This is an excerpt from Manning's book Spark in Action, Second Edition. Login to get full access to this book.
Compared to the previous examples in this chapter, note that you are not using awaitTermination() anymore; it is a blocking operation. You will use a loop to check whether the stream is active, using the isActive() method.
awaitTermination()
isActive()