Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Of concurrency and other demons
Rodrigo Graciano
January 16, 2021
Technology
0
39
Of concurrency and other demons
Talk about concurrency.
Initially presented at DawsCon with Hillmer Chona
Rodrigo Graciano
January 16, 2021
Tweet
Share
More Decks by Rodrigo Graciano
See All by Rodrigo Graciano
Batch Processing
graciano
0
85
Java 9 ao 17 - Oracle no TDC
graciano
0
30
KnoxJava - Java 9-17
graciano
0
93
Java 9 to Java 16: A review of recent changes to the language
graciano
0
81
Java 9 ao 15 - Evolução da Linguagem Java
graciano
0
170
Other Decks in Technology
See All in Technology
Swift Regex Builder
kumamotone
1
110
今どきのLinux事情
tokida
44
36k
oakのミドルウェアを書くときの技のらしきもの
toranoana
0
140
情報の世界 2022年度 第11回「都市のデータ」 #情報の世界 / Data of City 2022
yumulab
0
110
What's new in Vision
satotakeshi
0
220
【配布資料】複数データソースのデータを仮想化してまとめて分析してみよう(AWS、IBM Cloud)
tkhresk
0
100
要約 "Add Live Text interaction to your app"
ushisantoasobu
0
150
データ分析で切り拓け! エンジニアとしてのデータ分析職キャリア戦略
ksnt
0
180
Introduction To Technical Writing
olawanle_joel
0
100
Apple M1 CPUの脆弱性「PACMAN」について解説する
kuzushiki
0
110
EKSの運用あれこれ バージョンアップ編
tetsunosato
0
100
How to start with DDD when you have a Monolith
javujavichi
0
360
Featured
See All Featured
Done Done
chrislema
174
14k
Adopting Sorbet at Scale
ufuk
63
7.6k
How To Stay Up To Date on Web Technology
chriscoyier
780
250k
Reflections from 52 weeks, 52 projects
jeffersonlam
337
17k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
37
3.3k
Facilitating Awesome Meetings
lara
29
4k
5 minutes of I Can Smell Your CMS
philhawksworth
196
18k
What the flash - Photography Introduction
edds
62
10k
Mobile First: as difficult as doing things right
swwweet
213
7.5k
Code Reviewing Like a Champion
maltzj
506
37k
jQuery: Nuts, Bolts and Bling
dougneiner
56
6.4k
How New CSS Is Changing Everything About Graphic Design on the Web
jensimmons
213
11k
Transcript
None
➔ Software developer - Team lead ➔ Java Champion ➔
Medellin Java Users Group Leader ➔ hibernate/hibernate-validator Contributor ➔ Duke’s Choice Award Winner ➔ Eclipse Collections contributor
➔ Professional with 10+ years ➔ Principal Software Engineer -
NY ➔ NYJavaSIG Leader ➔ graciano.dev ➔ Twitter: @rodrigograciano
• • • •
• Concurrency when we have many task, largely independent, and
we use the same resource to do them at a time • Parallelism is when we want to do one task, and we split up in multiple subtasks
A Thread is an independent path of execution that allows
a program to operate more efficiently by doing multiple things at the same time. Threads can be used to perform complicated tasks in the background without interrupting the main program.
• Synchronous: when we wait to finish a task before
moving to the next one • Asynchronous: when we move to another task before it finishes
• Thread t = new Thread( ()-> this.doSomething( thing ));
t.start(); • ExecutorService executor = Executors.newFixedThreadPool( 10 ); Future<?> future = executor.submit( ()-> this.doSomething( thing )); • CompletableFuture.runAsync( ()-> this.doSomething( thing )); • Thread.builder().virtual().name("name").task(() -> this.doSomething( thing )).start();
None
None
Stream API CompletableFuture Creation Chained operations Return forEach runAsync thenAccept
/ thenRun void map supplyAsync thenApply CompletableFuture<U>
None
CompletableFuture<Void>::runAsync (Runnable runnable) <U> CompletableFuture<U>::supplyAsync (Supplier<U> supplier) CompletableFuture<Void>::runAsync (Runnable runnable,
Executor executor) <U> CompletableFuture<U>::supplyAsync (Supplier<U> supplier, Executor executor)
static ExecutorService newCachedThreadPool() static ExecutorService newFixedThreadPool (int nThreads) static ScheduledExecutorService
newScheduledThreadPool (int corePoolSize) static ExecutorService newSingleThreadExecutor() static ScheduledExecutorService newSingleThreadScheduledExecutor() static ExecutorService newWorkStealingPool()
T::get () throws InterruptedException , ExecutionException T::get (long timeout, TimeUnit
unit) throws InterruptedException , ExecutionException , TimeoutException T::getNow (T valueIfAbsent) T::join()
• • • •