Slide 1

Slide 1 text

Future in WebApp Kengo TODA

Slide 2

Slide 2 text

Agenda • What is Future • What is CompletableFuture • Common usage in WebApp

Slide 3

Slide 3 text

What is Future? • Proxy interface to get result of async operation • Similar with JavaScript’s Promise

Slide 4

Slide 4 text

Ask, and it will be given to you

Slide 5

Slide 5 text

How to implement method which returns Future instance? • Asynchronous Method Invocation (Java EE 6) • Creating Asynchronous Methods (Spring Framework)

Slide 6

Slide 6 text

What is CompletableFuture • New class from Java8, implements Future interface • Similar with ListenableFuture in Guava and Spring Framework

Slide 7

Slide 7 text

Apply result to Function,

Slide 8

Slide 8 text

or combine them.

Slide 9

Slide 9 text

Merit: connect result of Async I/O seamlessly auth add new post load timeline START END

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

When we use them? • When call async I/O • Datastore • Message Queue • Cache • RESTful API

Slide 12

Slide 12 text

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.

Slide 13

Slide 13 text

Keywords to google • Promise, Future • CompletableFuture • ListenableFuture (Guava & Spring Framework) • Function composition