Chapter 5Working with Resources

No one is useless in this world who lightens the burden of it to anyone else.

Charles Dickens

We may have been led to believe that the JVM automates all garbage collection (GC). It’s true that we could let the JVM handle it if we’re only using internal resources. However, GC is our responsibility if we use external resources, such as when we connect to databases, open files and sockets, or use native resources.

Java provides a few options to properly clean up resources, but, as we’ll see in this chapter, none are as effective as what we can do with lambda expressions. We’ll use lambda expressions to implement the execute around method (EAM) pattern, which gives us better control over sequencing of operations. ...

Get Functional Programming in Java now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.