Completable Future Example Save

Example project comparing Java's CompletableFuture and Future implementations

Project README

CompletableFuture, Future and Streams

This project uses a sample use case to compare Java's CompletableFuture with plain Future and other approaches like plain Java and the Stream API.

There is a story behind this code to make it more fun and, at the same time, to give a goal to the sample code so it's easier to compare. Welcome to the Java Bank Robbery with CompletableFutures, Futures and Streams.

The Java Bank Robbery

Blog

The comparison between these approaches, and a good introduction to CompletableFuture is available at The Practical Developer Site. I recommend you to read that guide to follow the codebase.

Code

The code is split into three main parts:

  • The main application class App, which runs the different code alternatives and shows the result.
  • The objects used to represent this story: Actions, Loot and Thief.
  • The alternatives used to execute the story:
    • SingleThreadOpenSafeLock contains two approaches, both single-threaded: plain, imperative Java and Stream API based.
    • FutureOpenSafeLock implements the plan using Java Futures, also in imperative-ish way.
    • CompletableFutureOpenSafeLock uses a few important methods of the CompletableFuture API to demonstrate how powerful it is to solve composed, multi-threaded problems.

Remember that the conclusions of the comparison are also included in the guide so, check it out now!

Open Source Agenda is not affiliated with "Completable Future Example" Project. README Source: mechero/completable-future-example
Stars
34
Open Issues
0
Last Commit
6 years ago

Open Source Agenda Badge

Open Source Agenda Rating