Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Future in WebApp (Java)

Future in WebApp (Java)

Short description about Future and CompletableFuture

Kengo TODA

July 17, 2016
Tweet

More Decks by Kengo TODA

Other Decks in Technology

Transcript

  1. What is Future? • Proxy interface to get result of

    async operation • Similar with JavaScript’s Promise
  2. How to implement method which returns Future instance? • Asynchronous

    Method Invocation (Java EE 6) • Creating Asynchronous Methods (Spring Framework)
  3. What is CompletableFuture • New class from Java8, implements Future

    interface • Similar with ListenableFuture in Guava and Spring Framework
  4. When we use them? • When call async I/O •

    Datastore • Message Queue • Cache • RESTful API
  5. Example: When we use them? • If you are service

    provider, • Public service API (interface for user) should return CompletableFuture instance if it may use I/O internally. • Then during I/O is running, your user can use current thread for other usage.
  6. Keywords to google • Promise, Future • CompletableFuture • ListenableFuture

    (Guava & Spring Framework) • Function composition