SlideShare a Scribd company logo
Back to the
CompletableFuture
Dmitry Vinnik
@DmitryVinnik dvinnik.com
What are our goals?
@DmitryVinnik dvinnik.com
Goals
Concurrency and Its Forms
Misconceptions of Concurrency
Workflows: How’s and Why’s
Why Concurrency?
@DmitryVinnik dvinnik.com
Multi-Core
Motivation
Microservices
CCSs
@DmitryVinnik dvinnik.com
Conclusion?
@DmitryVinnik dvinnik.com
Concurrency is
a New Reality
@DmitryVinnik dvinnik.com
Concurrency is
a Reality
@DmitryVinnik dvinnik.com
But!
@DmitryVinnik dvinnik.com
What’s in it for us?
@DmitryVinnik dvinnik.com
Benefits
No Idling ↑ UX
Abstraction
@DmitryVinnik dvinnik.com
Only good parts, right?
@DmitryVinnik dvinnik.com
Complexities
Thread
Safety
Performanc
e
Liveness
SDLC
@DmitryVinnik dvinnik.com
Complex
@DmitryVinnik dvinnik.com
But
@DmitryVinnik dvinnik.com
Beneficial
@DmitryVinnik dvinnik.com
Beautiful
@DmitryVinnik dvinnik.com
Remind anything?
@DmitryVinnik dvinnik.com
Concurrency
@DmitryVinnik dvinnik.com
is like
@DmitryVinnik dvinnik.com
@DmitryVinnik dvinnik.com
Concurrency & Sharks
@DmitryVinnik dvinnik.com
Concurrency & Sharks
@DmitryVinnik dvinnik.com
Fear
@DmitryVinnik dvinnik.com
Fear Admiration
@DmitryVinnik dvinnik.com
@DmitryVinnik dvinnik.com
Agenda
Single
Threading
Multi
Threading
Workflows
Single
Threading
Multi
Threading
Workflows
Concurrency
in Java
Concurrency
in Java
Do I even care?
@DmitryVinnik dvinnik.com
“My app is single threaded”
@DmitryVinnik dvinnik.com
“It is too complicated”
@DmitryVinnik dvinnik.com
“Not broken, don't touch it”
@DmitryVinnik dvinnik.com
Design For Concurrency
Programming
by Coincidence
Design by
Contract
Temporal
Coupling
Immutability
&
Atomicity
@DmitryVinnik dvinnik.com
Programming by
Coincidence
@DmitryVinnik dvinnik.com
“Can't tell if it is broken, or
if it never worked”
Programming by Coincidence
@DmitryVinnik dvinnik.com
Programming by Coincidence
@DmitryVinnik dvinnik.com
Design by Contract
@DmitryVinnik dvinnik.com
“Require No More,
Promise No Less”
Design by Contract
Quote from Bertrand Meyer,
“Design by Contract”
@DmitryVinnik dvinnik.com
Design by Contract
@DmitryVinnik dvinnik.com
Temporal Coupling
@DmitryVinnik dvinnik.com
“Do time & order matter?”
Temporal Coupling
@DmitryVinnik dvinnik.com
@DmitryVinnik dvinnik.com
Temporal Coupling
Agenda
Single
Threading
Multi
Threading
Workflows
Single
Threading
Multi
Threading
Workflows
Concurrency
in Java
Concurrency
in Java
Single
Threading
Multi
Threading
Multithreading
@DmitryVinnik dvinnik.com
What forms can it take?
@DmitryVinnik dvinnik.com
Multithreading Forms
Concurrent Form
Parallel Form
Asynchronous Form
Concurrent Form
Parallel Form
Asynchronous Form
@DmitryVinnik dvinnik.com
Form: Concurrency
@DmitryVinnik dvinnik.com
Form: Concurrency
Multiple
Tasks
Logically
Simultaneous
Multiple CPUs
Too Abstract?
@DmitryVinnik dvinnik.com
Let’s Code Something
@DmitryVinnik dvinnik.com
Goal: Develop App
@DmitryVinnik dvinnik.com
Form: Concurrency
What do we need?
@DmitryVinnik dvinnik.com
Form: Concurrency
Coffee, Code, Coffee, Code, Coffee, Code...
T1
@DmitryVinnik dvinnik.com
Form: Concurrency
Multithreading Forms
Concurrent Form
Parallel Form
Asynchronous Form
Concurrent Form
Parallel Form
Asynchronous Form
@DmitryVinnik dvinnik.com
Concurrent Form
Parallel Form
Form: Parallelism
dvinnik.com
Form: Parallelism
Multiple
(Sub)Tasks
Physically
Simultaneous
Multiple CPUs
Goal: Develop App
@DmitryVinnik dvinnik.com
Form: Parallelism
But now
@DmitryVinnik dvinnik.com
Form: Parallelism
As Ambidexter
@DmitryVinnik dvinnik.com
Form: Parallelism
T1
T2
@DmitryVinnik dvinnik.com
Form: Parallelism
Multithreading Forms
Concurrent Form
Parallel Form
Asynchronous Form
Concurrent Form
Parallel Form
Asynchronous Form
@DmitryVinnik dvinnik.com
Concurrent Form
Parallel FormParallel Form
Asynchronous Form
Form: Asynchrony
dvinnik.com
Fire & Forget
Non-Blocking
Multiple CPUs
@DmitryVinnik dvinnik.com
Form: Parallelism
Goal: Develop App
@DmitryVinnik dvinnik.com
Form: Asynchrony
Question
@DmitryVinnik dvinnik.com
Form: Asynchrony
Where does coffee
come from?
@DmitryVinnik dvinnik.com
Form: Asynchrony
Coffee Machine
@DmitryVinnik dvinnik.com
Form: Asynchrony
T1
aT1
@DmitryVinnik dvinnik.com
Form: Asynchrony
Agenda
Single
Threading
Multi
Threading
Workflows
Single
Threading
Multi
Threading
Workflows
Concurrency
in Java
Concurrency
in Java
Single
Threading
Multi
Threading
Multi
Threading
Concurrency
in Java
First...
@DmitryVinnik dvinnik.com
There were
Runnable & Thread
@DmitryVinnik dvinnik.com
Runnable
@DmitryVinnik dvinnik.com
No Input
Runnable
No Output
No Exception
@DmitryVinnik dvinnik.com
Runnable
Based
Thread
Min. 1 Main
Thread
Creation
Overhead
Then JDK5 was released
@DmitryVinnik dvinnik.com
Welcome
Concurrency API
@DmitryVinnik dvinnik.com
Concurrency API
ThreadLocal
Atomic
Operations
Thread Safe
Collections
And More
@DmitryVinnik dvinnik.com
Concurrency API
ThreadLocal
Atomic
Operations
Thread Safe
Collections
@DmitryVinnik dvinnik.com
ThreadLocal
Atomic
Operations
Thread Safe
Collections
ThreadLocal
@DmitryVinnik dvinnik.com
ThreadLocal
Resource
Confinement
Memory Leaks
Global Fields
Concurrency API
ThreadLocal
Atomic
Operations
Thread Safe
Collections
@DmitryVinnik dvinnik.com
ThreadLocal
Atomic
Operations
Thread Safe
Collections
ThreadLocal
Atomic
Operations
Atomic Operations
@DmitryVinnik dvinnik.com
Atomic Operations
Compound
Operations
↑ Speed
Compare
& Swap
Concurrency API
ThreadLocal
Atomic
Operations
Thread Safe
Collections
@DmitryVinnik dvinnik.com
ThreadLocal
Atomic
Operations
Thread Safe
Collections
ThreadLocal
Atomic
Operations
Atomic
Operations
Thread Safe
Collections
Thread Safe
Collections
Thread Safe Collections
@DmitryVinnik dvinnik.com
ConcurrentHashMap
Thread Safe Collections
Compound
Operations
↑ Speed
Configurable
Concurrency
Agenda
Single
Threading
Multi
Threading
Workflows
Single
Threading
Multi
Threading
Workflows
Concurrency
in Java
Concurrency
in Java
Single
Threading
Multi
Threading
Multi
Threading
Concurrency
in Java
Concurrency
in Java
Workflows
Where do we start?
@DmitryVinnik dvinnik.com
Promises in
JavaScript
Future/
Callable
Executor
Framework
Completable
Future
Workflows
Promises in
JavaScript
Future/
Callable
Executor
Framework
Completable
Future
@DmitryVinnik dvinnik.com
Callback Hell
in JavaScript
@DmitryVinnik dvinnik.com
Callback Hell in JavaScript
Verbose
Intuitive
@DmitryVinnik dvinnik.com
How do we fix this?
@DmitryVinnik dvinnik.com
Promises in JavaScript
@DmitryVinnik dvinnik.com
Promises in JavaScript
Before After
@DmitryVinnik dvinnik.com
Promises in
JavaScript
Future/
Callable
Executor
Framework
Completable
Future
Workflows
Promises in
JavaScript
Future/
Callable
Executor
Framework
Completable
Future
@DmitryVinnik dvinnik.com
Promises in
JavaScript
Future/
Callable
Runnable -> Thread
@DmitryVinnik dvinnik.com
Callable -> Future
@DmitryVinnik dvinnik.com
Callable
@DmitryVinnik dvinnik.com
No Input
Callable
Has Output
Has Exception
Future
@DmitryVinnik dvinnik.com
Completed in
the Future
Future
Executor
Framework
@DmitryVinnik dvinnik.com
Future sounds great!
@DmitryVinnik dvinnik.com
But how do we use it?
@DmitryVinnik dvinnik.com
Promises in
JavaScript
Future/
Callable
Executor
Framework
Completable
Future
Workflows
Promises in
JavaScript
Future/
Callable
Executor
Framework
Completable
Future
@DmitryVinnik dvinnik.com
Promises in
JavaScript
Future/
Callable
Future/
Callable
Executor
Framework
Executor Framework
@DmitryVinnik dvinnik.com
Executor Framework
Thread
Management
Declarative
Model
@DmitryVinnik dvinnik.com
Thread Pool
@DmitryVinnik dvinnik.com
Thread Pool
Thread
Management
Thread
Configuration
@DmitryVinnik dvinnik.com
Too many arguments...
@DmitryVinnik dvinnik.com
Factories to the rescue!
@DmitryVinnik dvinnik.com
Executor Factories
@DmitryVinnik dvinnik.com
Executor Factories
Single
Thread Pool
Cached
Thread Pool
Fixed
Thread Pool
Scheduled
Thread Pool
Work Stealing
Pool@DmitryVinnik dvinnik.com
Executor + Thread Pools
@DmitryVinnik dvinnik.com
ExecutorService
@DmitryVinnik dvinnik.com
ExecutorService
Async
Tasks
Thread
Pools
@DmitryVinnik dvinnik.com
Are we done?
@DmitryVinnik dvinnik.com
Future is not perfect!
@DmitryVinnik dvinnik.com
Not really...
@DmitryVinnik dvinnik.com
Future Pitfalls
Blocking
Operations
No Result
Chaining
Future
Combination
Exception
Handling
@DmitryVinnik dvinnik.com
Blocking Result Retrieval
@DmitryVinnik dvinnik.com
Blocking Result Retrieval
Blocking Get
Use Timeout
@DmitryVinnik dvinnik.com
No Futures Chaining
@DmitryVinnik dvinnik.com
Futures Chaining
No Workflows
Callback Hell
@DmitryVinnik dvinnik.com
Futures Combination
@DmitryVinnik dvinnik.com
Futures Combination
Blocking
InvokeAny
Blocking
InvokeAll()
@DmitryVinnik dvinnik.com
Exception Handling
@DmitryVinnik dvinnik.com
Exception Handling
Multiple
Exceptions
On Most
Operations
@DmitryVinnik dvinnik.com
So many issues...
@DmitryVinnik dvinnik.com
No worries!
@DmitryVinnik dvinnik.com
CompletableFuture
is here to help
@DmitryVinnik dvinnik.com
Promises in
JavaScript
Future/
Callable
Executor
Framework
Completable
Future
Workflows
Promises in
JavaScript
Future/
Callable
Executor
Framework
Completable
Future
@DmitryVinnik dvinnik.com
Promises in
JavaScript
Future/
Callable
Future/
Callable
Executor
Framework
Executor
Framework
Completable
Future
CompletableFuture
@DmitryVinnik dvinnik.com
CompletableFuture
Transformation
Composition
Chaining
Combination
Future Pitfalls
Blocking
Operations
No Result
Chaining
Future
Combination
Exception
Handling
@DmitryVinnik dvinnik.com
Let’s handle them with
CompletableFuture!
@DmitryVinnik dvinnik.com
Transformation/Chaining
@DmitryVinnik dvinnik.com
Transformation/Chainin
g
Workflows
ForkJoin
Pool
@DmitryVinnik dvinnik.com
Tasks Composition
@DmitryVinnik dvinnik.com
Tasks Composition
Workflows
Flat Map
@DmitryVinnik dvinnik.com
Controllable Futures
@DmitryVinnik dvinnik.com
Controllable Futures
Completable
Timeout/
Default Value
@DmitryVinnik dvinnik.com
Multiple Futures Control
@DmitryVinnik dvinnik.com
Multiple Futures Control
AllOf/AnyOf
Results Not
Formatted
@DmitryVinnik dvinnik.com
Tasks Combination
@DmitryVinnik dvinnik.com
Tasks Combination
Collect
Results
Sync/Async
@DmitryVinnik dvinnik.com
Exception Handling
@DmitryVinnik dvinnik.com
Exception Handling
@DmitryVinnik dvinnik.com
Call For Action
Embrace
Concurrency
Review Your
Application
Continue
Learning
@DmitryVinnik dvinnik.com
Q/A
@DmitryVinnik dvinnik.com
About Speaker
Twitter: @DmitryVinnik
Blog: dvinnik.com
LinkedIn: in/dmitry-vinnik/
Email: dmitry@dvinnik.com

More Related Content

PDF
Huge web apps web expo 2013
PDF
Need for Async: Hot pursuit for scalable applications
PDF
The Need for Async @ ScalaWorld
PDF
Programming Sideways: Asynchronous Techniques for Android
PPTX
Parallel and Asynchronous Programming - ITProDevConnections 2012 (English)
PDF
Why async matters
PPTX
C# 5 deep drive into asynchronous programming
PPTX
Parallel and Asynchronous Programming - ITProDevConnections 2012 (Greek)
Huge web apps web expo 2013
Need for Async: Hot pursuit for scalable applications
The Need for Async @ ScalaWorld
Programming Sideways: Asynchronous Techniques for Android
Parallel and Asynchronous Programming - ITProDevConnections 2012 (English)
Why async matters
C# 5 deep drive into asynchronous programming
Parallel and Asynchronous Programming - ITProDevConnections 2012 (Greek)

Similar to Back to the CompletableFuture: Concurrency in Action (20)

PDF
I see deadlocks : Matt Ellis - Techorama NL 2024
PDF
Asynchronous Programming in Android
PDF
Concurrency and parallel in .net
PDF
Asynchronous programming with Java & Spring
PPTX
Async/Await
PDF
Async Await for Mobile Apps
PDF
Concurrency, Parallelism And IO
PPTX
Think Async in Java 8
PPTX
Back to the [Completable] Future
PPT
Web services, WCF services and Multi Threading with Windows Forms
PPTX
Concurrency in c#
PPT
The Pillars Of Concurrency
PPTX
End to-end async and await
PPTX
Asynchronous programming - .NET Way
PDF
Consuming web services asynchronously with Futures and Rx Observables (svcc, ...
PDF
Java concurrency in practice
PDF
Our Concurrent Past; Our Distributed Future
PPT
Parallel Extentions to the .NET Framework
PPTX
Java concurrency in practice
PDF
Lie Cheat & Steal to build Hyper-Fast Applications using Event-Driven Archite...
I see deadlocks : Matt Ellis - Techorama NL 2024
Asynchronous Programming in Android
Concurrency and parallel in .net
Asynchronous programming with Java & Spring
Async/Await
Async Await for Mobile Apps
Concurrency, Parallelism And IO
Think Async in Java 8
Back to the [Completable] Future
Web services, WCF services and Multi Threading with Windows Forms
Concurrency in c#
The Pillars Of Concurrency
End to-end async and await
Asynchronous programming - .NET Way
Consuming web services asynchronously with Futures and Rx Observables (svcc, ...
Java concurrency in practice
Our Concurrent Past; Our Distributed Future
Parallel Extentions to the .NET Framework
Java concurrency in practice
Lie Cheat & Steal to build Hyper-Fast Applications using Event-Driven Archite...
Ad

More from Dmitry Vinnik (20)

PPTX
Leadership in Open Source and Why Companies Care
PPTX
Maximizing React Speed: Hands-On Guide to Debugging and Optimizing React Appl...
PPTX
Testing React with Jest: Validate Your Components Quickly!
PPTX
Cross-Platform CSS (Yes, it's Possible!) with Yoga
PPTX
Documentation Made Easy with Docusaurus
PPTX
Testing at Scale at Meta and Salesforce
PPTX
Fixing Broken Windows: Dealing with Legacy Systems, Poor Quality and Gaps
PPTX
Ent: Making Data Easy in Go
PPTX
The 10,000 Steps of Open Source Project Health
PPTX
Better Start: Enforcing Best Engineering Practices with Kotlin
PPTX
Testing Svelte with Jest: Validate Your Components Quickly!
PPTX
Developing Lightning Components for Communities.pptx
PDF
Hands on React Native: From Zero to Hero
PPTX
Remote Work: Gateway to Freedom
PPTX
Kindness Engineering: Focusing on What Matters
PPTX
Gauge + Taiko, BDD for Web Revived
PDF
Modern Web Testing: Going Beyond Selenium
PPTX
Do you even Function? Guiding Through Functional Interfaces
PPTX
From Robotium to Appium: Choose your Journey
PPTX
Stress Driven Development, and How to Avoid It
Leadership in Open Source and Why Companies Care
Maximizing React Speed: Hands-On Guide to Debugging and Optimizing React Appl...
Testing React with Jest: Validate Your Components Quickly!
Cross-Platform CSS (Yes, it's Possible!) with Yoga
Documentation Made Easy with Docusaurus
Testing at Scale at Meta and Salesforce
Fixing Broken Windows: Dealing with Legacy Systems, Poor Quality and Gaps
Ent: Making Data Easy in Go
The 10,000 Steps of Open Source Project Health
Better Start: Enforcing Best Engineering Practices with Kotlin
Testing Svelte with Jest: Validate Your Components Quickly!
Developing Lightning Components for Communities.pptx
Hands on React Native: From Zero to Hero
Remote Work: Gateway to Freedom
Kindness Engineering: Focusing on What Matters
Gauge + Taiko, BDD for Web Revived
Modern Web Testing: Going Beyond Selenium
Do you even Function? Guiding Through Functional Interfaces
From Robotium to Appium: Choose your Journey
Stress Driven Development, and How to Avoid It
Ad

Recently uploaded (20)

PPTX
assetexplorer- product-overview - presentation
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
top salesforce developer skills in 2025.pdf
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Nekopoi APK 2025 free lastest update
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
Reimagine Home Health with the Power of Agentic AI​
PPTX
ai tools demonstartion for schools and inter college
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
assetexplorer- product-overview - presentation
Odoo Companies in India – Driving Business Transformation.pdf
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
top salesforce developer skills in 2025.pdf
VVF-Customer-Presentation2025-Ver1.9.pptx
Nekopoi APK 2025 free lastest update
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
wealthsignaloriginal-com-DS-text-... (1).pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
CHAPTER 2 - PM Management and IT Context
Navsoft: AI-Powered Business Solutions & Custom Software Development
PTS Company Brochure 2025 (1).pdf.......
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Operating system designcfffgfgggggggvggggggggg
Design an Analysis of Algorithms I-SECS-1021-03
Reimagine Home Health with the Power of Agentic AI​
ai tools demonstartion for schools and inter college
Which alternative to Crystal Reports is best for small or large businesses.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025

Back to the CompletableFuture: Concurrency in Action

Editor's Notes

  • #5: How many of you have Macbook Pro? How many of you used AWS/Azure? Have you heard about Microservices
  • #6: How many of you have Macbook Pro? How many of you used AWS/Azure? Have you heard about Microservices Source: The Next Platform
  • #7: Change or die situation at this point World perspective
  • #8: Change or die situation at this point World perspective
  • #9: Change or die situation at this point World perspective
  • #19: Source: Pixabay
  • #20: Source: Pixabay
  • #21: Source: Pixabay
  • #22: Source: Pixabay
  • #25: This is our path for the rest of today This arrow is our talk
  • #26: This is our path for the rest of today This arrow is our talk
  • #27: This is our path for the rest of today This arrow is our talk
  • #28: This is our path for the rest of today This arrow is our talk
  • #29: Excuses to Avoid Concurrency: “My app is single threaded” “Concurrency is too complicated” “It works most of the time” “If it is not broken, don't touch it”
  • #30: Excuses to Avoid Concurrency: “My app is single threaded” “Concurrency is too complicated” “It works most of the time” “If it is not broken, don't touch it”
  • #31: Excuses to Avoid Concurrency: “My app is single threaded” “Concurrency is too complicated” “It works most of the time” “If it is not broken, don't touch it”
  • #32: Excuses to Avoid Concurrency: “My app is single threaded” “Concurrency is too complicated” “It works most of the time” “If it is not broken, don't touch it”
  • #33: “Always Design for Concurrency” - Pragmatic Programmer
  • #40: Good example is http clienta
  • #41: Good example is http clienta
  • #42: Good example is http clienta
  • #43: This is our path for the rest of today This arrow is our talk
  • #51: https://platformio.org/platformio-ide
  • #52: https://platformio.org/platformio-ide
  • #57: https://platformio.org/platformio-ide
  • #58: https://platformio.org/platformio-ide
  • #59: https://platformio.org/platformio-ide
  • #64: https://platformio.org/platformio-ide
  • #65: https://platformio.org/platformio-ide
  • #66: https://platformio.org/platformio-ide
  • #67: https://platformio.org/platformio-ide
  • #69: This is our path for the rest of today This arrow is our talk
  • #87: This is our path for the rest of today This arrow is our talk
  • #148: Will be sharing slides, github and useful links