https://github.com/mechero/completable-future-example
Example project comparing Java's CompletableFuture and Future implementations
https://github.com/mechero/completable-future-example
completablefuture future java thepracticaldeveloper
Last synced: 9 months ago
JSON representation
Example project comparing Java's CompletableFuture and Future implementations
- Host: GitHub
- URL: https://github.com/mechero/completable-future-example
- Owner: mechero
- Created: 2018-02-18T15:11:14.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-02-24T09:27:26.000Z (almost 8 years ago)
- Last Synced: 2025-03-30T18:43:55.997Z (10 months ago)
- Topics: completablefuture, future, java, thepracticaldeveloper
- Language: Java
- Size: 99.6 KB
- Stars: 34
- Watchers: 5
- Forks: 22
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this 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.

## Blog
The comparison between these approaches, and a good introduction to `CompletableFuture` is available at [The Practical Developer Site](https://thepracticaldeveloper.com/?p=1027). 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!](https://thepracticaldeveloper.com/?p=1027)