Suche senden
Hochladen
Completable future
•
2 gefällt mir
•
934 views
Srinivasan Raghvan
Folgen
Completable future . Presented at Java Users Group Bangalore
Weniger lesen
Mehr lesen
Software
Melden
Teilen
Melden
Teilen
1 von 24
Jetzt herunterladen
Downloaden Sie, um offline zu lesen
Empfohlen
Spring Framework - AOP
Spring Framework - AOP
Dzmitry Naskou
Asynchronous API in Java8, how to use CompletableFuture
Asynchronous API in Java8, how to use CompletableFuture
José Paumard
java memory management & gc
java memory management & gc
exsuns
Spring Boot
Spring Boot
Jiayun Zhou
Java 8 Workshop
Java 8 Workshop
Mario Fusco
Intro to Asynchronous Javascript
Intro to Asynchronous Javascript
Garrett Welson
From Java 11 to 17 and beyond.pdf
From Java 11 to 17 and beyond.pdf
José Paumard
REST APIs with Spring
REST APIs with Spring
Joshua Long
Empfohlen
Spring Framework - AOP
Spring Framework - AOP
Dzmitry Naskou
Asynchronous API in Java8, how to use CompletableFuture
Asynchronous API in Java8, how to use CompletableFuture
José Paumard
java memory management & gc
java memory management & gc
exsuns
Spring Boot
Spring Boot
Jiayun Zhou
Java 8 Workshop
Java 8 Workshop
Mario Fusco
Intro to Asynchronous Javascript
Intro to Asynchronous Javascript
Garrett Welson
From Java 11 to 17 and beyond.pdf
From Java 11 to 17 and beyond.pdf
José Paumard
REST APIs with Spring
REST APIs with Spring
Joshua Long
Asynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & Promises
Hùng Nguyễn Huy
Hello Armeria, Bye Spring
Hello Armeria, Bye Spring
Gihwan Kim
API Asynchrones en Java 8
API Asynchrones en Java 8
José Paumard
Idiomatic Kotlin
Idiomatic Kotlin
intelliyole
Clean Lambdas & Streams in Java8
Clean Lambdas & Streams in Java8
Victor Rentea
The New JavaScript: ES6
The New JavaScript: ES6
Rob Eisenberg
Spring Boot
Spring Boot
Jaran Flaath
From framework coupled code to #microservices through #DDD /by @codelytv
From framework coupled code to #microservices through #DDD /by @codelytv
CodelyTV
jq: JSON - Like a Boss
jq: JSON - Like a Boss
Bob Tiernay
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVC
IndicThreads
Introduction to java 8 stream api
Introduction to java 8 stream api
Vladislav sidlyarevich
Getting Started with Spring Authorization Server
Getting Started with Spring Authorization Server
VMware Tanzu
Java 17
Java 17
Mutlu Okuducu
Optional in Java 8
Optional in Java 8
Richard Walker
Spring Core
Spring Core
Pushan Bhattacharya
Java 9/10/11 - What's new and why you should upgrade
Java 9/10/11 - What's new and why you should upgrade
Simone Bordet
Java 9 New Features
Java 9 New Features
Ali BAKAN
Java 8 presentation
Java 8 presentation
Van Huong
Go Concurrency
Go Concurrency
jgrahamc
Asynchronous JavaScript Programming
Asynchronous JavaScript Programming
Haim Michael
Functional Programming With Lambdas and Streams in JDK8
Functional Programming With Lambdas and Streams in JDK8
IndicThreads
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
JAXLondon2014
Weitere ähnliche Inhalte
Was ist angesagt?
Asynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & Promises
Hùng Nguyễn Huy
Hello Armeria, Bye Spring
Hello Armeria, Bye Spring
Gihwan Kim
API Asynchrones en Java 8
API Asynchrones en Java 8
José Paumard
Idiomatic Kotlin
Idiomatic Kotlin
intelliyole
Clean Lambdas & Streams in Java8
Clean Lambdas & Streams in Java8
Victor Rentea
The New JavaScript: ES6
The New JavaScript: ES6
Rob Eisenberg
Spring Boot
Spring Boot
Jaran Flaath
From framework coupled code to #microservices through #DDD /by @codelytv
From framework coupled code to #microservices through #DDD /by @codelytv
CodelyTV
jq: JSON - Like a Boss
jq: JSON - Like a Boss
Bob Tiernay
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVC
IndicThreads
Introduction to java 8 stream api
Introduction to java 8 stream api
Vladislav sidlyarevich
Getting Started with Spring Authorization Server
Getting Started with Spring Authorization Server
VMware Tanzu
Java 17
Java 17
Mutlu Okuducu
Optional in Java 8
Optional in Java 8
Richard Walker
Spring Core
Spring Core
Pushan Bhattacharya
Java 9/10/11 - What's new and why you should upgrade
Java 9/10/11 - What's new and why you should upgrade
Simone Bordet
Java 9 New Features
Java 9 New Features
Ali BAKAN
Java 8 presentation
Java 8 presentation
Van Huong
Go Concurrency
Go Concurrency
jgrahamc
Asynchronous JavaScript Programming
Asynchronous JavaScript Programming
Haim Michael
Was ist angesagt?
(20)
Asynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & Promises
Hello Armeria, Bye Spring
Hello Armeria, Bye Spring
API Asynchrones en Java 8
API Asynchrones en Java 8
Idiomatic Kotlin
Idiomatic Kotlin
Clean Lambdas & Streams in Java8
Clean Lambdas & Streams in Java8
The New JavaScript: ES6
The New JavaScript: ES6
Spring Boot
Spring Boot
From framework coupled code to #microservices through #DDD /by @codelytv
From framework coupled code to #microservices through #DDD /by @codelytv
jq: JSON - Like a Boss
jq: JSON - Like a Boss
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVC
Introduction to java 8 stream api
Introduction to java 8 stream api
Getting Started with Spring Authorization Server
Getting Started with Spring Authorization Server
Java 17
Java 17
Optional in Java 8
Optional in Java 8
Spring Core
Spring Core
Java 9/10/11 - What's new and why you should upgrade
Java 9/10/11 - What's new and why you should upgrade
Java 9 New Features
Java 9 New Features
Java 8 presentation
Java 8 presentation
Go Concurrency
Go Concurrency
Asynchronous JavaScript Programming
Asynchronous JavaScript Programming
Ähnlich wie Completable future
Functional Programming With Lambdas and Streams in JDK8
Functional Programming With Lambdas and Streams in JDK8
IndicThreads
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
JAXLondon2014
Lambdas And Streams in JDK8
Lambdas And Streams in JDK8
Simon Ritter
What's New in Java 8
What's New in Java 8
javafxpert
JSR 236 Concurrency Utils for EE presentation for JavaOne 2013 (CON7948)
JSR 236 Concurrency Utils for EE presentation for JavaOne 2013 (CON7948)
Fred Rowe
Lambdas : Beyond The Basics
Lambdas : Beyond The Basics
Simon Ritter
"Quantum" Performance Effects
"Quantum" Performance Effects
Sergey Kuksenko
Jakarta Concurrency: Present and Future
Jakarta Concurrency: Present and Future
Payara
Proxy deep-dive java-one_20151027_001
Proxy deep-dive java-one_20151027_001
Sven Ruppert
GlassFish BOF
GlassFish BOF
glassfish
Cloud Native Serverless Java — Orkhan Gasimov
Cloud Native Serverless Java — Orkhan Gasimov
GlobalLogic Ukraine
JavaOne San Francisco 2013 - Servlet 3.1 (JSR 340)
JavaOne San Francisco 2013 - Servlet 3.1 (JSR 340)
Shing Wai Chan
Interactive Java Support to your tool -- The JShell API and Architecture
Interactive Java Support to your tool -- The JShell API and Architecture
JavaDayUA
2015 Java update and roadmap, JUG sevilla
2015 Java update and roadmap, JUG sevilla
Trisha Gee
Java ee7 1hour
Java ee7 1hour
Frank Rodriguez
Batch Applications for the Java Platform
Batch Applications for the Java Platform
Sivakumar Thyagarajan
OTN Tour 2013: What's new in java EE 7
OTN Tour 2013: What's new in java EE 7
Bruno Borges
Design Patterns - Part 1 of 2
Design Patterns - Part 1 of 2
Savio Sebastian
MySQL Proxy. A powerful, flexible MySQL toolbox.
MySQL Proxy. A powerful, flexible MySQL toolbox.
Miguel Araújo
Java Cloud and Container Ready
Java Cloud and Container Ready
CodeOps Technologies LLP
Ähnlich wie Completable future
(20)
Functional Programming With Lambdas and Streams in JDK8
Functional Programming With Lambdas and Streams in JDK8
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Lambdas And Streams in JDK8
Lambdas And Streams in JDK8
What's New in Java 8
What's New in Java 8
JSR 236 Concurrency Utils for EE presentation for JavaOne 2013 (CON7948)
JSR 236 Concurrency Utils for EE presentation for JavaOne 2013 (CON7948)
Lambdas : Beyond The Basics
Lambdas : Beyond The Basics
"Quantum" Performance Effects
"Quantum" Performance Effects
Jakarta Concurrency: Present and Future
Jakarta Concurrency: Present and Future
Proxy deep-dive java-one_20151027_001
Proxy deep-dive java-one_20151027_001
GlassFish BOF
GlassFish BOF
Cloud Native Serverless Java — Orkhan Gasimov
Cloud Native Serverless Java — Orkhan Gasimov
JavaOne San Francisco 2013 - Servlet 3.1 (JSR 340)
JavaOne San Francisco 2013 - Servlet 3.1 (JSR 340)
Interactive Java Support to your tool -- The JShell API and Architecture
Interactive Java Support to your tool -- The JShell API and Architecture
2015 Java update and roadmap, JUG sevilla
2015 Java update and roadmap, JUG sevilla
Java ee7 1hour
Java ee7 1hour
Batch Applications for the Java Platform
Batch Applications for the Java Platform
OTN Tour 2013: What's new in java EE 7
OTN Tour 2013: What's new in java EE 7
Design Patterns - Part 1 of 2
Design Patterns - Part 1 of 2
MySQL Proxy. A powerful, flexible MySQL toolbox.
MySQL Proxy. A powerful, flexible MySQL toolbox.
Java Cloud and Container Ready
Java Cloud and Container Ready
Kürzlich hochgeladen
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
smiwainfosol
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
YashikaSharma391629
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
Velvetech LLC
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Cizo Technology Services
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
Lionel Briand
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
Akihiro Suda
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
Dinusha Kumarasiri
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
Alina Yurenko
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
Hr365.us smith
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
VICTOR MAESTRE RAMIREZ
Cyber security and its impact on E commerce
Cyber security and its impact on E commerce
manigoyal112
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Drew Moseley
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
StefanoLambiase
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Mater
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
31events.com
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Matt Ray
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
jennyeacort
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
FerryKemperman
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
Hanief Utama
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Stefano Stabellini
Kürzlich hochgeladen
(20)
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
Cyber security and its impact on E commerce
Cyber security and its impact on E commerce
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Completable future
1.
2.
3.
Completable Future Srinivasan Raghavan Senior
Member of Technical Staff Java Platform Group Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
4.
Copyright © 2015,
Oracle and/or its affiliates. All rights reserved. | Program Agenda java.util.Future Introduction Cloud Services Design and the fight for Performance CompletableFuture and power of parallelism Building powerful libraries with Completable Future 1 2 3 4 4
5.
Copyright © 2015,
Oracle and/or its affiliates. All rights reserved. | java.util.Future Introduction • Before jdk1.5 , no java.util.concurrent.*, only threads ,synchronized primitives • W ite o e , u a ywhe e ? – g eat su ess , But u it a illio ti es , wo k the sa e ? ig uestio • In came java.util.concurrent.* with executor service and future tasks and many other concurrency constructs • A java.util.Future is a construct which holds a result available at a later time • Future is asynchronous , but its not non-blocking 5
6.
Copyright © 2015,
Oracle and/or its affiliates. All rights reserved. | The Executor Service and Future Task • Executors contains pool of threads which accepts tasks and supplies to the Future • When a task is submitted to the executor it returns a future and future.get() would block the computation until it ends 6 ExecutorService executorService = Executors.newFixedThreadPool(20); Future<Integer> future = executorService.submit(new Callable<Integer>() { @Override public Integer call() throws Exception { return 42; } }); System.out.println(future.get()); executorService.shutdown(); User Executor Task (Callable) Future
7.
Copyright © 2015,
Oracle and/or its affiliates. All rights reserved. | What can be done ? • Future can allow computation in the background so improving performance • Future.get() would block the thread and wait till the computation is complete and get the result • Can get an exception if there is a failure • future.cancel() cancels the computation • future.isDone() checks the computation is complete • A d that’s it ///// 7 ExecutorService executorService = Executors.newFixedThreadPool(20); Future<Integer> future = executorService.submit(new Callable<Integer>() { @Override public Integer call() throws Exception { //Some complex work return 42; } }); System.out.println(future.get()); executorService.shutdown();
8.
Copyright © 2015,
Oracle and/or its affiliates. All rights reserved. | Distributed Cloud Services Design and the fight for Performance 8
9.
Copyright © 2015,
Oracle and/or its affiliates. All rights reserved. | A Typical distributed cloud service 9 Get data from service provider 1 Get data from service provider 3 Get data from service provider 2 Combine Data Response(result) Request(userData,reuestParams) Processing for analytics Process data for the user Generate recommendation
10.
Copyright © 2015,
Oracle and/or its affiliates. All rights reserved. | Performance Bottlenecks and impacts • Java.util.Future can help in parallelism • But it cannot help with pipeline the tasks and managing the thread pool for you • Future does not supports call backs and chaining of operations • Building libraries with future can be complictaed • Performing in a serial way can impact the latency big time • It can destroy all benefits of having distributed services • No amount of horizontal and vertical scaling can help • Without dynamic services offerings business can be affected 10
11.
Copyright © 2015,
Oracle and/or its affiliates. All rights reserved. | CompletableFuture and power of parallelism 11
12.
Copyright © 2015,
Oracle and/or its affiliates. All rights reserved. | What is Completable future ? • Its new addition to java 8 • Asynchronous, allows registering asyc callbacks just like java scripts, event-driven programming model • Support for depending functions to be triggered on completion • Each stage can be executed with different executor pool • Also comes with a built in thread pool for executing tasks • Built in lambda support ,super flexible and scalable api 12
13.
Copyright © 2015,
Oracle and/or its affiliates. All rights reserved. | Basics 13 CompletableFuture<String> future = CompletableFuture.supplyAsync(new Supplier<String>() { @Override public String get() { // ...long running... return "42"; } }, executor1); future.get(); //Come on ... we are in JDK 8 !!! CompletableFuture<String> future = CompletableFuture .supplyAsync(() -> "42",executor1); future.get();
14.
Copyright © 2015,
Oracle and/or its affiliates. All rights reserved. | Lambdas , Crash Recap 14
15.
Copyright © 2015,
Oracle and/or its affiliates. All rights reserved. | Lambdas • Function definition that is not bound to an identifier 15 /** * * This is a piece of code that illustrate how lambdas work in Java 8 * * Given an example * * f(x) = 2x+5; * * given x= 2 ; f(x) = 9 ; * * z(x)= f(g(x)) where g(x) =3x+5 * * z(x) = 2(3x+5) +5 = 6x+15 12+15 = 27 * * */ public class LambdaUnderStanding2 { @FunctionalInterface static interface Funct { int apply(int x); default Funct compose(Funct before) { return (x) -> apply(before.apply(x)); } } public static void main(String[] args) { Funct annoymous = new Funct() { @Override public int apply(int x) { return 2 * x + 5;; } }; Funct funct = (x) -> 2 * x + 5; System.out.println(funct.apply(2)); Funct composed = funct.compose((x) -> 3 * x + 5); System.out.println(composed.apply(2)); } }
16.
Copyright © 2015,
Oracle and/or its affiliates. All rights reserved. | Java 8 Functional Interface 16 Predicate<Integer> test = (x) -> x> 10; Function<Integer, Integer> function = (x) -> 3 * x + 5; Consumer<Integer> print = (x) -> System.out.println(x); BiFunction<Integer, Integer, Integer> biFunction = (x, y) -> 3 * x + 4* y + 2; Supplier<Integer> supplier = () -> Integer.MAX_VALUE;
17.
Copyright © 2015,
Oracle and/or its affiliates. All rights reserved. | thenApply() -transformations 17 /** * Classic call back present in javascript or scala . * theApply is like run this function when the result *arrives from previous stages */ final CompletableFuture<Integer> future1 = CompletableFuture .supplyAsync(() -> "42", executor1).thenApply( (x) -> Integer.parseInt(x)); /** * thenApply is trasformative changing CompletableFuture<Integer> to * CompletableFuture<Double> */ CompletableFuture<Double> future2 = CompletableFuture .supplyAsync(() -> "42", executor1) .thenApply((x) -> Integer.parseInt(x)) .thenApply(r -> r * r * Math.PI); /** * U can supply a differnt executor pool for thenApply */ CompletableFuture<Double> future = CompletableFuture .supplyAsync(() -> "42", executor1) .thenApplyAsync((x) -> Integer.parseInt(x), executor2) .thenApplyAsync(r -> r * r * Math.PI, executor2);
18.
Copyright © 2015,
Oracle and/or its affiliates. All rights reserved. | thenCombine() , whenComplete() –completion 18 final CompletableFuture<Integer> future = CompletableFuture .supplyAsync(() -> "32", executor1).thenApply( (x) -> Integer.parseInt(x)); CompletableFuture.supplyAsync(() -> "42", executor2) .thenApply((x) -> Integer.parseInt(x)) .thenCombine(future, (x, y) -> x + y) .thenAccept((result) -> System.out.println(result)); /** * When complete is final stage where it can check the execpetions * propagated and pass results through it */ final CompletableFuture<Integer> future = CompletableFuture .supplyAsync(() -> "42", executor1) .thenApply((x) -> Integer.parseInt(x)) .whenComplete( (x, throwable) -> { if (throwable != null) { Logger.getAnonymousLogger().log(Level.SEVERE, "Logging" + throwable); } else { Logger.getAnonymousLogger().log(Level.FINE, " Passed " + x); } });
19.
Copyright © 2015,
Oracle and/or its affiliates. All rights reserved. | thenCombine() allOf() - combining futures 19 /** * Combining two dependent futures */ final CompletableFuture<Integer> future = CompletableFuture .supplyAsync(() -> "32", executor1).thenApply( (x) -> Integer.parseInt(x)); CompletableFuture.supplyAsync(() -> "42", executor2) .thenApply((x) -> Integer.parseInt(x)) .thenCombine(future, (x, y) -> x + y) .thenAccept((result) -> System.out.println(result)); /** * Combining n futures unrelated */ CompletableFuture<Void> future2 = CompletableFuture .supplyAsync(() -> "42", executor1) .thenApplyAsync((x) -> Integer.parseInt(x), executor2) .thenAcceptAsync( (x) -> Logger.getAnonymousLogger().log(Level.FINE, "Logging" + x), executor2); CompletableFuture<Void> future1 = CompletableFuture .supplyAsync(() -> “ ", executor1) .thenApplyAsync((x) -> Integer.parseInt(x), executor2) .thenAcceptAsync( (x) -> Logger.getAnonymousLogger().log(Level.FINE, "Logging" + x), executor2); CompletableFuture.allOf(future1,future2).join();
20.
Copyright © 2015,
Oracle and/or its affiliates. All rights reserved. | Building powerful libraries with Completable Future 20
21.
Copyright © 2015,
Oracle and/or its affiliates. All rights reserved. | Building powerful libraries with completable futures • Building scalable service orchestrator • Building dynamic http client framework • Improve parallelism in existing services with are done serial • Building libraries tuned for vertical scalability 21
22.
Copyright © 2015,
Oracle and/or its affiliates. All rights reserved. | References • https://docs.oracle.com/javase/tutorial/ • https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Completa bleFuture.html • http://cs.oswego.edu/mailman/listinfo/concurrency-interest • https://github.com/srinivasanraghavan/functional 22
23.
Copyright © 2015,
Oracle and/or its affiliates. All rights reserved. | Questions ? 23
Jetzt herunterladen