Coder Social home page Coder Social logo

completable-future-example's Introduction

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!

completable-future-example's People

Contributors

mechero avatar

Watchers

Rohan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.