SlideShare a Scribd company logo
1
Nicety of java 8 multithreading for advanced
Maksym Voroniy
Software Architect of GlobalLogic
2
Common points01
3
History
Text
The Dream Time sharing
Stone Age Intel 80386
Multiple
data
multiple
handlers
Multiple
processo
rs
Multiple
data
single
handler
Hyper threading
IBM 360
CUDA
Multicore
Today
4
Point #1
Maurice Herlihy & Nir Shavit “The Art of Multiprocessor Programming”
5
Atomicity vs Consistence
static int a = 5;
a *= 3;
int b = 22;
b += a;
mov EAX, 5
mov ds:[a], EAX
mul 3
mov ds:[a], EAX
mov EBX, 22
add EBX, EAX;vs add EBX,ds:[a]
atomicity
consistence
6
Java 8 FAA vs CAS02
7
Nicety #1 - Java 8 Atomics
http://ashkrit.blogspot.com/2014/02/atomicinteger-java-7-vs-java-8.html
fetch-and-add vs compare-and-swap (CAS)
JDK 8 - AtomicInteger
public final int getAndIncrement() {
return unsafe.getAndAddInt(
this, valueOffset, 1);
}
JDK7 - AtomicInteger
public final int getAndIncrement() {
for (;;) {
int current = get();
int next = current + 1;
if (compareAndSet(current, next))
return current;
}
}
8
Why Atomic important?
Text
ConcurrentHashMap<>
Collections.synchronizedMap(new HashMap<>())
• ConcurrentLinkedDeque/Queue
• ConcurrentSkipListSet/Map
• ConcurrentHashMap
• wait-free, if every concurrent operation is guaranteed to be
finished in a finite number of steps
• lock-free, if some concurrent operations are guaranteed to
be finished in a finite number of steps.
DARE
develop concurrent hash-map
TODAY tomorrow
9
ConcurrentHashMap
StampedLock goes to stage
Text
Simple cache implementation (value by key):
(T key, Map<T, V> map) -> {
return map.get(i);
}
synchronizedMap(new HashMap<>())
(T key, Map<T, V> map) -> {
synchronized (map){
return map.get(i);
}
}
HashMap + ReadWriteLock
(T key, Map<T, V> map) -> {
Lock l = rwLock.readLock();
l.lock();
try {
return map.get(i);
} finally {
l.unlock();
}}
10
StampedLock goes to stage (II)
Text
HashMap + StampedLock
(T key, Map<T, V> map) -> {
long l = stampedLock.readLock();
try {
return map.get(i);
} finally {
stampedLock.unlockRead(l);
}}
HashMap + StampedLock+Optimistic
(T key, Map<T, V> map) -> {
long stamp = optimisticLock.tryOptimisticRead();
Integer r = map.get(i);
if (!optimisticLock.validate(stamp)) {
stamp = optimisticLock.readLock();
try {
return map.get(i);
} finally {
optimisticLock.unlockRead(stamp);
}
}
return r;
}
200`000 op for 10
Threads
Nanoseconds
ConcurrentHashMap 72645.057
Optimistic 359819.982
StampedLock 1303853.525
ReadWriteLock 1326939.766
Locked 1922399.053
11
Java 8 Parallelism03
12
.parallelStream()
Text
//from Oracle tutorial:
double average = roster
.parallelStream()
.filter(p -> p.getGender() == Person.Sex.MALE)
.mapToInt(Person::getAge)
.average()
.getAsDouble()
• Java runtime partitions the stream into
multiple substreams. Aggregate operations
iterate over and process these substreams in
parallel and then combine the results
static ExecutorService newWorkStealingPool()
static ExecutorService newFixedThreadPool(int nThreads)
static ScheduledExecutorService newScheduledThreadPool(int corePoolSize)
static ExecutorService newCachedThreadPool(ThreadFactory threadFactory)
• Work Stealing (An idle thread steals work from a thread having tasks queued up more than it
can process currently)
• Ability to recursively decompose the tasks and collect the results. (Apparently, this requirement
must have popped up along with the conception of the notion of parallel processing... but lacked
a solid implementation framework in Java till Java 7)
ForkJoinPool
13
The trap!
List<SomeClass> list = // A list of objects
list.parallelStream()
.map(this::veryLongProcessing)
.collect(toList());
partition
Stream-1
Stream-2
Stream-3
Core -1 Core -2
ForkJoinPool forkJoinPool = new ForkJoinPool(2);
forkJoinPool.submit(() ->
list.parallel()
.map(this::veryLongProcessing)
.collect(toList())
).get();
"Arranges to asynchronously execute this task in the pool the
current task is running in, if applicable, or using the
ForkJoinPool.commonPool() if not in
ForkJoinPool()"
14
The Future
Text
Time sharing
Stone Age Intel 80386
Hyper threading
IBM 360
CUDA
Multicore
HTMSTM
15
Future direction
• How Databases works (SQL& NoSQL)
• Quantum computing
• Advanced data structures (R-Tree, B-Tree, Trie, Skip-lists, Heaps…)
http://goo.gl/forms/9LauaeJBlO
N
16
Thank you!
Any Questions?
Ad

Recommended

Nicety of Java 8 Multithreading
Nicety of Java 8 Multithreading
GlobalLogic Ukraine
 
Engineering fast indexes
Engineering fast indexes
Daniel Lemire
 
Deep dumpster diving 2010
Deep dumpster diving 2010
RonnBlack
 
Engineering fast indexes (Deepdive)
Engineering fast indexes (Deepdive)
Daniel Lemire
 
Next Generation Indexes For Big Data Engineering (ODSC East 2018)
Next Generation Indexes For Big Data Engineering (ODSC East 2018)
Daniel Lemire
 
On Mining Bitcoins - Fundamentals & Outlooks
On Mining Bitcoins - Fundamentals & Outlooks
Filip Maertens
 
Virtual machine and javascript engine
Virtual machine and javascript engine
Duoyi Wu
 
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
NAVER / MusicPlatform
 
The Ring programming language version 1.3 book - Part 84 of 88
The Ring programming language version 1.3 book - Part 84 of 88
Mahmoud Samir Fayed
 
Functional Reactive Programming with RxJS
Functional Reactive Programming with RxJS
stefanmayer13
 
To Swift 2...and Beyond!
To Swift 2...and Beyond!
Scott Gardner
 
Cascadia.js: Don't Cross the Streams
Cascadia.js: Don't Cross the Streams
mattpodwysocki
 
Fast Wavelet Tree Construction in Practice
Fast Wavelet Tree Construction in Practice
Rakuten Group, Inc.
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in C
Steffen Wenz
 
Powered by Python - PyCon Germany 2016
Powered by Python - PyCon Germany 2016
Steffen Wenz
 
Efficient Two-level Homomorphic Encryption in Prime-order Bilinear Groups and...
Efficient Two-level Homomorphic Encryption in Prime-order Bilinear Groups and...
MITSUNARI Shigeo
 
Compose Async with RxJS
Compose Async with RxJS
Kyung Yeol Kim
 
Cluj Big Data Meetup - Big Data in Practice
Cluj Big Data Meetup - Big Data in Practice
Steffen Wenz
 
Grand centraldispatch
Grand centraldispatch
Yuumi Yoshida
 
Java 7 new features
Java 7 new features
Aliaksandr Kazlou
 
Practical Two-level Homomorphic Encryption in Prime-order Bilinear Groups
Practical Two-level Homomorphic Encryption in Prime-order Bilinear Groups
MITSUNARI Shigeo
 
Modern c++ Memory Management
Modern c++ Memory Management
Alan Uthoff
 
The Ring programming language version 1.5.4 book - Part 59 of 185
The Ring programming language version 1.5.4 book - Part 59 of 185
Mahmoud Samir Fayed
 
Using Deep Learning (Computer Vision) to Search for Oil and Gas
Using Deep Learning (Computer Vision) to Search for Oil and Gas
Sorin Peste
 
Zone.js 2017
Zone.js 2017
Jia Li
 
Csw2016 gawlik bypassing_differentdefenseschemes
Csw2016 gawlik bypassing_differentdefenseschemes
CanSecWest
 
Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013
aleks-f
 
Counter Wars (JEEConf 2016)
Counter Wars (JEEConf 2016)
Alexey Fyodorov
 
Concurrency in Java
Concurrency in Java
Allan Huang
 
Programming with Threads in Java
Programming with Threads in Java
koji lin
 

More Related Content

What's hot (20)

The Ring programming language version 1.3 book - Part 84 of 88
The Ring programming language version 1.3 book - Part 84 of 88
Mahmoud Samir Fayed
 
Functional Reactive Programming with RxJS
Functional Reactive Programming with RxJS
stefanmayer13
 
To Swift 2...and Beyond!
To Swift 2...and Beyond!
Scott Gardner
 
Cascadia.js: Don't Cross the Streams
Cascadia.js: Don't Cross the Streams
mattpodwysocki
 
Fast Wavelet Tree Construction in Practice
Fast Wavelet Tree Construction in Practice
Rakuten Group, Inc.
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in C
Steffen Wenz
 
Powered by Python - PyCon Germany 2016
Powered by Python - PyCon Germany 2016
Steffen Wenz
 
Efficient Two-level Homomorphic Encryption in Prime-order Bilinear Groups and...
Efficient Two-level Homomorphic Encryption in Prime-order Bilinear Groups and...
MITSUNARI Shigeo
 
Compose Async with RxJS
Compose Async with RxJS
Kyung Yeol Kim
 
Cluj Big Data Meetup - Big Data in Practice
Cluj Big Data Meetup - Big Data in Practice
Steffen Wenz
 
Grand centraldispatch
Grand centraldispatch
Yuumi Yoshida
 
Java 7 new features
Java 7 new features
Aliaksandr Kazlou
 
Practical Two-level Homomorphic Encryption in Prime-order Bilinear Groups
Practical Two-level Homomorphic Encryption in Prime-order Bilinear Groups
MITSUNARI Shigeo
 
Modern c++ Memory Management
Modern c++ Memory Management
Alan Uthoff
 
The Ring programming language version 1.5.4 book - Part 59 of 185
The Ring programming language version 1.5.4 book - Part 59 of 185
Mahmoud Samir Fayed
 
Using Deep Learning (Computer Vision) to Search for Oil and Gas
Using Deep Learning (Computer Vision) to Search for Oil and Gas
Sorin Peste
 
Zone.js 2017
Zone.js 2017
Jia Li
 
Csw2016 gawlik bypassing_differentdefenseschemes
Csw2016 gawlik bypassing_differentdefenseschemes
CanSecWest
 
Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013
aleks-f
 
Counter Wars (JEEConf 2016)
Counter Wars (JEEConf 2016)
Alexey Fyodorov
 
The Ring programming language version 1.3 book - Part 84 of 88
The Ring programming language version 1.3 book - Part 84 of 88
Mahmoud Samir Fayed
 
Functional Reactive Programming with RxJS
Functional Reactive Programming with RxJS
stefanmayer13
 
To Swift 2...and Beyond!
To Swift 2...and Beyond!
Scott Gardner
 
Cascadia.js: Don't Cross the Streams
Cascadia.js: Don't Cross the Streams
mattpodwysocki
 
Fast Wavelet Tree Construction in Practice
Fast Wavelet Tree Construction in Practice
Rakuten Group, Inc.
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in C
Steffen Wenz
 
Powered by Python - PyCon Germany 2016
Powered by Python - PyCon Germany 2016
Steffen Wenz
 
Efficient Two-level Homomorphic Encryption in Prime-order Bilinear Groups and...
Efficient Two-level Homomorphic Encryption in Prime-order Bilinear Groups and...
MITSUNARI Shigeo
 
Compose Async with RxJS
Compose Async with RxJS
Kyung Yeol Kim
 
Cluj Big Data Meetup - Big Data in Practice
Cluj Big Data Meetup - Big Data in Practice
Steffen Wenz
 
Grand centraldispatch
Grand centraldispatch
Yuumi Yoshida
 
Practical Two-level Homomorphic Encryption in Prime-order Bilinear Groups
Practical Two-level Homomorphic Encryption in Prime-order Bilinear Groups
MITSUNARI Shigeo
 
Modern c++ Memory Management
Modern c++ Memory Management
Alan Uthoff
 
The Ring programming language version 1.5.4 book - Part 59 of 185
The Ring programming language version 1.5.4 book - Part 59 of 185
Mahmoud Samir Fayed
 
Using Deep Learning (Computer Vision) to Search for Oil and Gas
Using Deep Learning (Computer Vision) to Search for Oil and Gas
Sorin Peste
 
Zone.js 2017
Zone.js 2017
Jia Li
 
Csw2016 gawlik bypassing_differentdefenseschemes
Csw2016 gawlik bypassing_differentdefenseschemes
CanSecWest
 
Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013
aleks-f
 
Counter Wars (JEEConf 2016)
Counter Wars (JEEConf 2016)
Alexey Fyodorov
 

Similar to Nicety of java 8 multithreading for advanced, Max Voronoy (20)

Concurrency in Java
Concurrency in Java
Allan Huang
 
Programming with Threads in Java
Programming with Threads in Java
koji lin
 
Java Concurrency in Practice
Java Concurrency in Practice
Alina Dolgikh
 
Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)
Martijn Verburg
 
Optimizing your java applications for multi core hardware
Optimizing your java applications for multi core hardware
IndicThreads
 
Hs java open_party
Hs java open_party
Open Party
 
Concurrency on the JVM
Concurrency on the JVM
Bernhard Huemer
 
jvm/java - towards lock-free concurrency
jvm/java - towards lock-free concurrency
Arvind Kalyan
 
Java Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
Java Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
JAX London
 
Concurrency and Multithreading Demistified - Reversim Summit 2014
Concurrency and Multithreading Demistified - Reversim Summit 2014
Haim Yadid
 
Java concurrency
Java concurrency
ducquoc_vn
 
Working With Concurrency In Java 8
Working With Concurrency In Java 8
Heartin Jacob
 
Concurrency in Java
Concurrency in Java
Lakshmi Narasimhan
 
Concurrent Programming in Java
Concurrent Programming in Java
Lakshmi Narasimhan
 
Java Concurrency
Java Concurrency
Carol McDonald
 
Java Concurrency and Performance | Multi Threading | Concurrency | Java Conc...
Java Concurrency and Performance | Multi Threading | Concurrency | Java Conc...
Anand Narayanan
 
Modern Java Concurrency
Modern Java Concurrency
Ben Evans
 
Modern Java Concurrency (Devoxx Nov/2011)
Modern Java Concurrency (Devoxx Nov/2011)
Martijn Verburg
 
Concurrency
Concurrency
Ankur Maheshwari
 
Java Concurrency, A(nother) Peek Under the Hood [Code One 2019]
Java Concurrency, A(nother) Peek Under the Hood [Code One 2019]
David Buck
 
Concurrency in Java
Concurrency in Java
Allan Huang
 
Programming with Threads in Java
Programming with Threads in Java
koji lin
 
Java Concurrency in Practice
Java Concurrency in Practice
Alina Dolgikh
 
Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)
Martijn Verburg
 
Optimizing your java applications for multi core hardware
Optimizing your java applications for multi core hardware
IndicThreads
 
Hs java open_party
Hs java open_party
Open Party
 
jvm/java - towards lock-free concurrency
jvm/java - towards lock-free concurrency
Arvind Kalyan
 
Java Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
Java Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
JAX London
 
Concurrency and Multithreading Demistified - Reversim Summit 2014
Concurrency and Multithreading Demistified - Reversim Summit 2014
Haim Yadid
 
Java concurrency
Java concurrency
ducquoc_vn
 
Working With Concurrency In Java 8
Working With Concurrency In Java 8
Heartin Jacob
 
Concurrent Programming in Java
Concurrent Programming in Java
Lakshmi Narasimhan
 
Java Concurrency and Performance | Multi Threading | Concurrency | Java Conc...
Java Concurrency and Performance | Multi Threading | Concurrency | Java Conc...
Anand Narayanan
 
Modern Java Concurrency
Modern Java Concurrency
Ben Evans
 
Modern Java Concurrency (Devoxx Nov/2011)
Modern Java Concurrency (Devoxx Nov/2011)
Martijn Verburg
 
Java Concurrency, A(nother) Peek Under the Hood [Code One 2019]
Java Concurrency, A(nother) Peek Under the Hood [Code One 2019]
David Buck
 
Ad

More from Sigma Software (20)

Fast is Best. Using .NET MinimalAPIs
Fast is Best. Using .NET MinimalAPIs
Sigma Software
 
"Are you developing or declining? Don't become an IT-dinosaur"
"Are you developing or declining? Don't become an IT-dinosaur"
Sigma Software
 
Michael Smolin, "Decrypting customer's cultural code"
Michael Smolin, "Decrypting customer's cultural code"
Sigma Software
 
Max Kunytsia, “Why is continuous product discovery better than continuous del...
Max Kunytsia, “Why is continuous product discovery better than continuous del...
Sigma Software
 
Marcelino Moreno, "Product Management Mindset"
Marcelino Moreno, "Product Management Mindset"
Sigma Software
 
Andrii Pastushok, "Product Discovery in Outsourcing - What, When, and How"
Andrii Pastushok, "Product Discovery in Outsourcing - What, When, and How"
Sigma Software
 
Elena Turkenych “BA vs PM: Who' the right person, for the right job, with the...
Elena Turkenych “BA vs PM: Who' the right person, for the right job, with the...
Sigma Software
 
Eleonora Budanova “BA+PM+DEV team: how to build the synergy”
Eleonora Budanova “BA+PM+DEV team: how to build the synergy”
Sigma Software
 
Stoyan Atanasov “How crucial is the BA role in an IT Project"
Stoyan Atanasov “How crucial is the BA role in an IT Project"
Sigma Software
 
Olexandra Kovalyova, "Equivalence Partitioning, Boundary Values ​​Analysis, C...
Olexandra Kovalyova, "Equivalence Partitioning, Boundary Values ​​Analysis, C...
Sigma Software
 
Yana Lysa — "Decision Tables, State-Transition testing, Pairwase Testing"
Yana Lysa — "Decision Tables, State-Transition testing, Pairwase Testing"
Sigma Software
 
VOLVO x HACK SPRINT
VOLVO x HACK SPRINT
Sigma Software
 
Business digitalization trends and challenges
Business digitalization trends and challenges
Sigma Software
 
Дмитро Терещенко, "How to secure your application with Secure SDLC"
Дмитро Терещенко, "How to secure your application with Secure SDLC"
Sigma Software
 
Яна Лиса, “Ефективні методи написання хороших мануальних тестових сценаріїв”
Яна Лиса, “Ефективні методи написання хороших мануальних тестових сценаріїв”
Sigma Software
 
Тетяна Осетрова, “Модель зрілості розподіленної проектної команди”
Тетяна Осетрова, “Модель зрілості розподіленної проектної команди”
Sigma Software
 
Training solutions and content creation
Training solutions and content creation
Sigma Software
 
False news - false truth: tips & tricks how to avoid them
False news - false truth: tips & tricks how to avoid them
Sigma Software
 
Анна Бойко, "Хороший контракт vs очікування клієнтів. Що вбереже вас, якщо вд...
Анна Бойко, "Хороший контракт vs очікування клієнтів. Що вбереже вас, якщо вд...
Sigma Software
 
Дмитрий Лапшин, "The importance of TEX and Internal Quality. How explain and ...
Дмитрий Лапшин, "The importance of TEX and Internal Quality. How explain and ...
Sigma Software
 
Fast is Best. Using .NET MinimalAPIs
Fast is Best. Using .NET MinimalAPIs
Sigma Software
 
"Are you developing or declining? Don't become an IT-dinosaur"
"Are you developing or declining? Don't become an IT-dinosaur"
Sigma Software
 
Michael Smolin, "Decrypting customer's cultural code"
Michael Smolin, "Decrypting customer's cultural code"
Sigma Software
 
Max Kunytsia, “Why is continuous product discovery better than continuous del...
Max Kunytsia, “Why is continuous product discovery better than continuous del...
Sigma Software
 
Marcelino Moreno, "Product Management Mindset"
Marcelino Moreno, "Product Management Mindset"
Sigma Software
 
Andrii Pastushok, "Product Discovery in Outsourcing - What, When, and How"
Andrii Pastushok, "Product Discovery in Outsourcing - What, When, and How"
Sigma Software
 
Elena Turkenych “BA vs PM: Who' the right person, for the right job, with the...
Elena Turkenych “BA vs PM: Who' the right person, for the right job, with the...
Sigma Software
 
Eleonora Budanova “BA+PM+DEV team: how to build the synergy”
Eleonora Budanova “BA+PM+DEV team: how to build the synergy”
Sigma Software
 
Stoyan Atanasov “How crucial is the BA role in an IT Project"
Stoyan Atanasov “How crucial is the BA role in an IT Project"
Sigma Software
 
Olexandra Kovalyova, "Equivalence Partitioning, Boundary Values ​​Analysis, C...
Olexandra Kovalyova, "Equivalence Partitioning, Boundary Values ​​Analysis, C...
Sigma Software
 
Yana Lysa — "Decision Tables, State-Transition testing, Pairwase Testing"
Yana Lysa — "Decision Tables, State-Transition testing, Pairwase Testing"
Sigma Software
 
Business digitalization trends and challenges
Business digitalization trends and challenges
Sigma Software
 
Дмитро Терещенко, "How to secure your application with Secure SDLC"
Дмитро Терещенко, "How to secure your application with Secure SDLC"
Sigma Software
 
Яна Лиса, “Ефективні методи написання хороших мануальних тестових сценаріїв”
Яна Лиса, “Ефективні методи написання хороших мануальних тестових сценаріїв”
Sigma Software
 
Тетяна Осетрова, “Модель зрілості розподіленної проектної команди”
Тетяна Осетрова, “Модель зрілості розподіленної проектної команди”
Sigma Software
 
Training solutions and content creation
Training solutions and content creation
Sigma Software
 
False news - false truth: tips & tricks how to avoid them
False news - false truth: tips & tricks how to avoid them
Sigma Software
 
Анна Бойко, "Хороший контракт vs очікування клієнтів. Що вбереже вас, якщо вд...
Анна Бойко, "Хороший контракт vs очікування клієнтів. Що вбереже вас, якщо вд...
Sigma Software
 
Дмитрий Лапшин, "The importance of TEX and Internal Quality. How explain and ...
Дмитрий Лапшин, "The importance of TEX and Internal Quality. How explain and ...
Sigma Software
 
Ad

Recently uploaded (20)

Best MLM Compensation Plans for Network Marketing Success in 2025
Best MLM Compensation Plans for Network Marketing Success in 2025
LETSCMS Pvt. Ltd.
 
The Anti-Masterclass Live - Peak of Data & AI 2025
The Anti-Masterclass Live - Peak of Data & AI 2025
Safe Software
 
Smadav Pro 2025 Rev 15.4 Crack Full Version With Registration Key
Smadav Pro 2025 Rev 15.4 Crack Full Version With Registration Key
joybepari360
 
Porting Qt 5 QML Modules to Qt 6 Webinar
Porting Qt 5 QML Modules to Qt 6 Webinar
ICS
 
Artificial Intelligence Workloads and Data Center Management
Artificial Intelligence Workloads and Data Center Management
SandeepKS52
 
Introduction to Agile Frameworks for Product Managers.pdf
Introduction to Agile Frameworks for Product Managers.pdf
Ali Vahed
 
NVIDIA GPU Technologies for AI and High-Performance Computing
NVIDIA GPU Technologies for AI and High-Performance Computing
SandeepKS52
 
Best Practice for LLM Serving in the Cloud
Best Practice for LLM Serving in the Cloud
Alluxio, Inc.
 
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
Hassan Abid
 
Streamlining CI/CD with FME Flow: A Practical Guide
Streamlining CI/CD with FME Flow: A Practical Guide
Safe Software
 
Azure AI Foundry: The AI app and agent factory
Azure AI Foundry: The AI app and agent factory
Maxim Salnikov
 
Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
WSO2
 
Test Case Design Techniques – Practical Examples & Best Practices in Software...
Test Case Design Techniques – Practical Examples & Best Practices in Software...
Muhammad Fahad Bashir
 
Advance Doctor Appointment Booking App With Online Payment
Advance Doctor Appointment Booking App With Online Payment
AxisTechnolabs
 
Making significant Software Architecture decisions
Making significant Software Architecture decisions
Bert Jan Schrijver
 
Modern Platform Engineering with Choreo - The AI-Native Internal Developer Pl...
Modern Platform Engineering with Choreo - The AI-Native Internal Developer Pl...
WSO2
 
arctitecture application system design os dsa
arctitecture application system design os dsa
za241967
 
HYBRIDIZATION OF ALKANES AND ALKENES ...
HYBRIDIZATION OF ALKANES AND ALKENES ...
karishmaduhijod1
 
Women in Tech: Marketo Engage User Group - June 2025 - AJO with AWS
Women in Tech: Marketo Engage User Group - June 2025 - AJO with AWS
BradBedford3
 
Best MLM Compensation Plans for Network Marketing Success in 2025
Best MLM Compensation Plans for Network Marketing Success in 2025
LETSCMS Pvt. Ltd.
 
The Anti-Masterclass Live - Peak of Data & AI 2025
The Anti-Masterclass Live - Peak of Data & AI 2025
Safe Software
 
Smadav Pro 2025 Rev 15.4 Crack Full Version With Registration Key
Smadav Pro 2025 Rev 15.4 Crack Full Version With Registration Key
joybepari360
 
Porting Qt 5 QML Modules to Qt 6 Webinar
Porting Qt 5 QML Modules to Qt 6 Webinar
ICS
 
Artificial Intelligence Workloads and Data Center Management
Artificial Intelligence Workloads and Data Center Management
SandeepKS52
 
Introduction to Agile Frameworks for Product Managers.pdf
Introduction to Agile Frameworks for Product Managers.pdf
Ali Vahed
 
NVIDIA GPU Technologies for AI and High-Performance Computing
NVIDIA GPU Technologies for AI and High-Performance Computing
SandeepKS52
 
Best Practice for LLM Serving in the Cloud
Best Practice for LLM Serving in the Cloud
Alluxio, Inc.
 
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
Hassan Abid
 
Streamlining CI/CD with FME Flow: A Practical Guide
Streamlining CI/CD with FME Flow: A Practical Guide
Safe Software
 
Azure AI Foundry: The AI app and agent factory
Azure AI Foundry: The AI app and agent factory
Maxim Salnikov
 
Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
WSO2
 
Test Case Design Techniques – Practical Examples & Best Practices in Software...
Test Case Design Techniques – Practical Examples & Best Practices in Software...
Muhammad Fahad Bashir
 
Advance Doctor Appointment Booking App With Online Payment
Advance Doctor Appointment Booking App With Online Payment
AxisTechnolabs
 
Making significant Software Architecture decisions
Making significant Software Architecture decisions
Bert Jan Schrijver
 
Modern Platform Engineering with Choreo - The AI-Native Internal Developer Pl...
Modern Platform Engineering with Choreo - The AI-Native Internal Developer Pl...
WSO2
 
arctitecture application system design os dsa
arctitecture application system design os dsa
za241967
 
HYBRIDIZATION OF ALKANES AND ALKENES ...
HYBRIDIZATION OF ALKANES AND ALKENES ...
karishmaduhijod1
 
Women in Tech: Marketo Engage User Group - June 2025 - AJO with AWS
Women in Tech: Marketo Engage User Group - June 2025 - AJO with AWS
BradBedford3
 

Nicety of java 8 multithreading for advanced, Max Voronoy

  • 1. 1 Nicety of java 8 multithreading for advanced Maksym Voroniy Software Architect of GlobalLogic
  • 3. 3 History Text The Dream Time sharing Stone Age Intel 80386 Multiple data multiple handlers Multiple processo rs Multiple data single handler Hyper threading IBM 360 CUDA Multicore Today
  • 4. 4 Point #1 Maurice Herlihy & Nir Shavit “The Art of Multiprocessor Programming”
  • 5. 5 Atomicity vs Consistence static int a = 5; a *= 3; int b = 22; b += a; mov EAX, 5 mov ds:[a], EAX mul 3 mov ds:[a], EAX mov EBX, 22 add EBX, EAX;vs add EBX,ds:[a] atomicity consistence
  • 6. 6 Java 8 FAA vs CAS02
  • 7. 7 Nicety #1 - Java 8 Atomics http://ashkrit.blogspot.com/2014/02/atomicinteger-java-7-vs-java-8.html fetch-and-add vs compare-and-swap (CAS) JDK 8 - AtomicInteger public final int getAndIncrement() { return unsafe.getAndAddInt( this, valueOffset, 1); } JDK7 - AtomicInteger public final int getAndIncrement() { for (;;) { int current = get(); int next = current + 1; if (compareAndSet(current, next)) return current; } }
  • 8. 8 Why Atomic important? Text ConcurrentHashMap<> Collections.synchronizedMap(new HashMap<>()) • ConcurrentLinkedDeque/Queue • ConcurrentSkipListSet/Map • ConcurrentHashMap • wait-free, if every concurrent operation is guaranteed to be finished in a finite number of steps • lock-free, if some concurrent operations are guaranteed to be finished in a finite number of steps. DARE develop concurrent hash-map TODAY tomorrow
  • 9. 9 ConcurrentHashMap StampedLock goes to stage Text Simple cache implementation (value by key): (T key, Map<T, V> map) -> { return map.get(i); } synchronizedMap(new HashMap<>()) (T key, Map<T, V> map) -> { synchronized (map){ return map.get(i); } } HashMap + ReadWriteLock (T key, Map<T, V> map) -> { Lock l = rwLock.readLock(); l.lock(); try { return map.get(i); } finally { l.unlock(); }}
  • 10. 10 StampedLock goes to stage (II) Text HashMap + StampedLock (T key, Map<T, V> map) -> { long l = stampedLock.readLock(); try { return map.get(i); } finally { stampedLock.unlockRead(l); }} HashMap + StampedLock+Optimistic (T key, Map<T, V> map) -> { long stamp = optimisticLock.tryOptimisticRead(); Integer r = map.get(i); if (!optimisticLock.validate(stamp)) { stamp = optimisticLock.readLock(); try { return map.get(i); } finally { optimisticLock.unlockRead(stamp); } } return r; } 200`000 op for 10 Threads Nanoseconds ConcurrentHashMap 72645.057 Optimistic 359819.982 StampedLock 1303853.525 ReadWriteLock 1326939.766 Locked 1922399.053
  • 12. 12 .parallelStream() Text //from Oracle tutorial: double average = roster .parallelStream() .filter(p -> p.getGender() == Person.Sex.MALE) .mapToInt(Person::getAge) .average() .getAsDouble() • Java runtime partitions the stream into multiple substreams. Aggregate operations iterate over and process these substreams in parallel and then combine the results static ExecutorService newWorkStealingPool() static ExecutorService newFixedThreadPool(int nThreads) static ScheduledExecutorService newScheduledThreadPool(int corePoolSize) static ExecutorService newCachedThreadPool(ThreadFactory threadFactory) • Work Stealing (An idle thread steals work from a thread having tasks queued up more than it can process currently) • Ability to recursively decompose the tasks and collect the results. (Apparently, this requirement must have popped up along with the conception of the notion of parallel processing... but lacked a solid implementation framework in Java till Java 7) ForkJoinPool
  • 13. 13 The trap! List<SomeClass> list = // A list of objects list.parallelStream() .map(this::veryLongProcessing) .collect(toList()); partition Stream-1 Stream-2 Stream-3 Core -1 Core -2 ForkJoinPool forkJoinPool = new ForkJoinPool(2); forkJoinPool.submit(() -> list.parallel() .map(this::veryLongProcessing) .collect(toList()) ).get(); "Arranges to asynchronously execute this task in the pool the current task is running in, if applicable, or using the ForkJoinPool.commonPool() if not in ForkJoinPool()"
  • 14. 14 The Future Text Time sharing Stone Age Intel 80386 Hyper threading IBM 360 CUDA Multicore HTMSTM
  • 15. 15 Future direction • How Databases works (SQL& NoSQL) • Quantum computing • Advanced data structures (R-Tree, B-Tree, Trie, Skip-lists, Heaps…) http://goo.gl/forms/9LauaeJBlO N