SlideShare ist ein Scribd-Unternehmen logo
1 von 32
Evolution of JDK Tools
for Multithreaded Programming
Maksym Fastovets
Senior Software Engineer
Motivation
You should go at least to one or two conferences a
year. Because 365 days of the year you can't be
excited all the time. But if you go to a conference you
get excited by the new technology and everything and
you get to learn new people and talk about stuff and
then you're excited again and you get back to work and
you... you have more energy.
1
- Some guy from some conf
Conference
or Tech Talk
2
What this talk is about?
- A little bit of terminology and models of concurrent programming
- Why should we care?
- From Thread to CompletableFuture in examples
What this talk is NOT about?
- It’s not about deep look into components of java.util.concurrent
- And it’s not about detailed overview of NIO, reactive, or asynchronous
programming in Java
- It’s neither about real use-cases nor about benchmarking or
performance measure
3
Process vs Thread
In computing, a process is the instance of a computer program that
is being executed. It contains the program code and its activity.
Depending on the operating system (OS), a process may be made up
of multiple threads of execution that execute instructions concurrently
In computer science, a thread of execution is the smallest sequence
of programmed instructions that can be managed independently by a
scheduler, which is typically a part of the operating system. The
implementation of threads and processes differs between operating
systems, but in most cases a thread is a component of a process.
4
Models of concurrent computing
5
Model with shared objects (shared memory)
Shared memory
Shared Object 1
Shared Object 2
Shared Object M
Thread 1
Thread 2
Thread N
C/C++...
6
Model with shared objects (shared memory)
7
Messages passing model
akka (written in Scala, has Java and Scala API), Erlang...
We can model parallel computing by letting threads send
messages to each other instead of giving them shared objects.
8
Happened-before model
Java, C#...
In computer science, the happened-before relation (denoted: →) is
a relation between the result of two events, such that if one event
should happen before another event, the result must reflect that, even
if those events are in reality executed out of order (usually to optimize
program flow). This involves ordering events based on the potential
causal relationship of pairs of events in a concurrent system,
especially asynchronous distributed systems.
∀ e,f, where e ≠ f if e ↛ f and f ↛ e, then e is parallel to f
(denoted: e || f)
9
Global time model
Global time does not exist due to physical limitations, so this
model is not used in evidence, but it helps in visualizing various
processes.
10
http://neerc.ifmo.ru/wiki/index.php?title=%D0%91%D0%B0%D0%B7%D0%BE%D0%B2%D1%8B%D0%B5_%D0%BE%D0%BF%D1%80%D0%B5%D0%B4%D0%B5%D0%BB%D
0%B5%D0%BD%D0%B8%D1%8F_%D0%B8_%D1%84%D0%BE%D1%80%D0%BC%D0%B0%D0%BB%D0%B8%D0%B7%D0%BC
Monitor (synchronization)
In concurrent programming, a monitor is a synchronization
construct that allows threads to have both mutual exclusion and
the ability to wait (block) for a certain condition to become true.
Monitors also have a mechanism for signaling other threads that
their condition has been met.
Mutual exclusion is a property of concurrency control, which is
instituted for the purpose of preventing race conditions; it is the
requirement that one thread of execution never enters its critical
section at the same time that another concurrent thread of
execution enters its own critical section.
11
Monitor (synchronization)
In Java Monitor is represented by
- synchronized keyword
- wait(), notify(), notifyAll() methods of java.lang.Object (so
technically each object in Java is a monitor)
12
Why should I care?
13
Moore's law and “The free lunch is over”
Moore's law is the observation that the number of transistors in a
dense integrated circuit doubles about every two years.
14
(MHz)
http://www.ni.com/white-paper/6390/en
Amdahl's law
The maximum speedup of code with N threads when S portion of
it is serial:
- If all code is parallel (S = 0) then speedup equals to number of
threads
- If just 5% of code is serial the maximum possible speedup of code is
20
15
Concurrency in Java
16
1996... 2003 2004 2005 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014...
1.0 5.0 6 7 8
java.lang.Thread
java.util.concurrent
(jsr166)
jsr166x
Project Lambda
Fork/Join Framework
(jsr166y)
Let’s take numerical integration as the problem
17
Integration: The Rectangle Method
A1 = f(x1)(b-a)/n
Sequential solution
18
Solution with java.lang.Thread
19
Solution with java.lang.Thread
20
Spliterator
Collector
Solution with ExecutorService
21
Solution with ExecutorService
22
Spliterator
Collector
Solution with ForkJoinPool
23
Solution with ForkJoinPool
24
Spliterator
Collector
Solution with ForkJoinPool
25
Solution with CompletableFuture
26
Spliterator
Collector
Solution with Streams
27
Collector
Spliterator
What else?
- RxJava (Project Reactor)
- java.util.concurrent.Flow (Java 9)
- ...
28
List of references
- Roman Elizarov’s talks on JMM and parallel computing
- https://youtu.be/D8DXW7wlGDE
- https://youtu.be/hxIRyqHRnjE
- Andrey Rodionov, “From Java Threads to Lambdas”:
https://youtu.be/W82D9eUn6q8
- Aleksey Shipilëv, “ForkJoinPool in Java 8”: https://youtu.be/t0dGLFtRR9c
- Manning, “The Well-Grounded Java Developer”
- Wiki
- Process vs Thread
- https://en.wikipedia.org/wiki/Happened-before
- https://en.wikipedia.org/wiki/Monitor_(synchronization)
29
Github repo with talk code sources
- https://github.com/fastovezz/evolution-of-multithreaded
Questions
Thank you!
maksym.fastovets@globallogic.com

Weitere ähnliche Inhalte

Mehr von GlobalLogic Ukraine

GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
GlobalLogic Ukraine
 

Mehr von GlobalLogic Ukraine (20)

Страх і сила помилок - IT Inside від GlobalLogic Education
Страх і сила помилок - IT Inside від GlobalLogic EducationСтрах і сила помилок - IT Inside від GlobalLogic Education
Страх і сила помилок - IT Inside від GlobalLogic Education
 
GlobalLogic .NET Webinar #2 “Azure RBAC and Managed Identity”
GlobalLogic .NET Webinar #2 “Azure RBAC and Managed Identity”GlobalLogic .NET Webinar #2 “Azure RBAC and Managed Identity”
GlobalLogic .NET Webinar #2 “Azure RBAC and Managed Identity”
 
GlobalLogic QA Webinar “What does it take to become a Test Engineer”
GlobalLogic QA Webinar “What does it take to become a Test Engineer”GlobalLogic QA Webinar “What does it take to become a Test Engineer”
GlobalLogic QA Webinar “What does it take to become a Test Engineer”
 
“How to Secure Your Applications With a Keycloak?
“How to Secure Your Applications With a Keycloak?“How to Secure Your Applications With a Keycloak?
“How to Secure Your Applications With a Keycloak?
 
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
GlobalLogic Machine Learning Webinar “Advanced Statistical Methods for Linear...
 
GlobalLogic Machine Learning Webinar “Statistical learning of linear regressi...
GlobalLogic Machine Learning Webinar “Statistical learning of linear regressi...GlobalLogic Machine Learning Webinar “Statistical learning of linear regressi...
GlobalLogic Machine Learning Webinar “Statistical learning of linear regressi...
 
GlobalLogic C++ Webinar “The Minimum Knowledge to Become a C++ Developer”
GlobalLogic C++ Webinar “The Minimum Knowledge to Become a C++ Developer”GlobalLogic C++ Webinar “The Minimum Knowledge to Become a C++ Developer”
GlobalLogic C++ Webinar “The Minimum Knowledge to Become a C++ Developer”
 
Embedded Webinar #17 "Low-level Network Testing in Embedded Devices Development"
Embedded Webinar #17 "Low-level Network Testing in Embedded Devices Development"Embedded Webinar #17 "Low-level Network Testing in Embedded Devices Development"
Embedded Webinar #17 "Low-level Network Testing in Embedded Devices Development"
 
GlobalLogic Webinar "Introduction to Embedded QA"
GlobalLogic Webinar "Introduction to Embedded QA"GlobalLogic Webinar "Introduction to Embedded QA"
GlobalLogic Webinar "Introduction to Embedded QA"
 
C++ Webinar "Why Should You Learn C++ in 2021-22?"
C++ Webinar "Why Should You Learn C++ in 2021-22?"C++ Webinar "Why Should You Learn C++ in 2021-22?"
C++ Webinar "Why Should You Learn C++ in 2021-22?"
 
GlobalLogic Test Automation Live Testing Session “Android Behind UI — Testing...
GlobalLogic Test Automation Live Testing Session “Android Behind UI — Testing...GlobalLogic Test Automation Live Testing Session “Android Behind UI — Testing...
GlobalLogic Test Automation Live Testing Session “Android Behind UI — Testing...
 
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
 
GlobalLogic Azure TechTalk ONLINE “Marketing Data Lake in Azure”
GlobalLogic Azure TechTalk ONLINE “Marketing Data Lake in Azure”GlobalLogic Azure TechTalk ONLINE “Marketing Data Lake in Azure”
GlobalLogic Azure TechTalk ONLINE “Marketing Data Lake in Azure”
 
GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”
GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”
GlobalLogic Test Automation Online TechTalk “Playwright — A New Hope”
 
Java Webinar #13 “Where Is My Development Zone?”
Java Webinar #13 “Where Is My Development Zone?”Java Webinar #13 “Where Is My Development Zone?”
Java Webinar #13 “Where Is My Development Zone?”
 
NET Webinar #1 "Is There a Life Outside the Entity Framework"
NET Webinar #1 "Is There a Life Outside the Entity Framework"NET Webinar #1 "Is There a Life Outside the Entity Framework"
NET Webinar #1 "Is There a Life Outside the Entity Framework"
 
GlobalLogic С/C++/Embedded Live Coding Challenge. Basic graph algorithms
GlobalLogic С/C++/Embedded Live Coding Challenge. Basic graph algorithmsGlobalLogic С/C++/Embedded Live Coding Challenge. Basic graph algorithms
GlobalLogic С/C++/Embedded Live Coding Challenge. Basic graph algorithms
 
Online TechTalk “Flutter Mobile Development”
Online TechTalk “Flutter Mobile Development”Online TechTalk “Flutter Mobile Development”
Online TechTalk “Flutter Mobile Development”
 
Online TechTalk  "Patterns in Embedded SW Design"
Online TechTalk  "Patterns in Embedded SW Design"Online TechTalk  "Patterns in Embedded SW Design"
Online TechTalk  "Patterns in Embedded SW Design"
 
Сloud Webinar #1 “Architecture of Highly Loaded Geo-Distributed Applications”
Сloud Webinar #1 “Architecture of Highly Loaded Geo-Distributed Applications”Сloud Webinar #1 “Architecture of Highly Loaded Geo-Distributed Applications”
Сloud Webinar #1 “Architecture of Highly Loaded Geo-Distributed Applications”
 

Kürzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Kürzlich hochgeladen (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

Evolution of JDK Tools for Multithreaded Programming

  • 1. Evolution of JDK Tools for Multithreaded Programming Maksym Fastovets Senior Software Engineer
  • 2. Motivation You should go at least to one or two conferences a year. Because 365 days of the year you can't be excited all the time. But if you go to a conference you get excited by the new technology and everything and you get to learn new people and talk about stuff and then you're excited again and you get back to work and you... you have more energy. 1 - Some guy from some conf
  • 4. What this talk is about? - A little bit of terminology and models of concurrent programming - Why should we care? - From Thread to CompletableFuture in examples What this talk is NOT about? - It’s not about deep look into components of java.util.concurrent - And it’s not about detailed overview of NIO, reactive, or asynchronous programming in Java - It’s neither about real use-cases nor about benchmarking or performance measure 3
  • 5. Process vs Thread In computing, a process is the instance of a computer program that is being executed. It contains the program code and its activity. Depending on the operating system (OS), a process may be made up of multiple threads of execution that execute instructions concurrently In computer science, a thread of execution is the smallest sequence of programmed instructions that can be managed independently by a scheduler, which is typically a part of the operating system. The implementation of threads and processes differs between operating systems, but in most cases a thread is a component of a process. 4
  • 6. Models of concurrent computing 5
  • 7. Model with shared objects (shared memory) Shared memory Shared Object 1 Shared Object 2 Shared Object M Thread 1 Thread 2 Thread N C/C++... 6
  • 8. Model with shared objects (shared memory) 7
  • 9. Messages passing model akka (written in Scala, has Java and Scala API), Erlang... We can model parallel computing by letting threads send messages to each other instead of giving them shared objects. 8
  • 10. Happened-before model Java, C#... In computer science, the happened-before relation (denoted: →) is a relation between the result of two events, such that if one event should happen before another event, the result must reflect that, even if those events are in reality executed out of order (usually to optimize program flow). This involves ordering events based on the potential causal relationship of pairs of events in a concurrent system, especially asynchronous distributed systems. ∀ e,f, where e ≠ f if e ↛ f and f ↛ e, then e is parallel to f (denoted: e || f) 9
  • 11. Global time model Global time does not exist due to physical limitations, so this model is not used in evidence, but it helps in visualizing various processes. 10 http://neerc.ifmo.ru/wiki/index.php?title=%D0%91%D0%B0%D0%B7%D0%BE%D0%B2%D1%8B%D0%B5_%D0%BE%D0%BF%D1%80%D0%B5%D0%B4%D0%B5%D0%BB%D 0%B5%D0%BD%D0%B8%D1%8F_%D0%B8_%D1%84%D0%BE%D1%80%D0%BC%D0%B0%D0%BB%D0%B8%D0%B7%D0%BC
  • 12. Monitor (synchronization) In concurrent programming, a monitor is a synchronization construct that allows threads to have both mutual exclusion and the ability to wait (block) for a certain condition to become true. Monitors also have a mechanism for signaling other threads that their condition has been met. Mutual exclusion is a property of concurrency control, which is instituted for the purpose of preventing race conditions; it is the requirement that one thread of execution never enters its critical section at the same time that another concurrent thread of execution enters its own critical section. 11
  • 13. Monitor (synchronization) In Java Monitor is represented by - synchronized keyword - wait(), notify(), notifyAll() methods of java.lang.Object (so technically each object in Java is a monitor) 12
  • 14. Why should I care? 13
  • 15. Moore's law and “The free lunch is over” Moore's law is the observation that the number of transistors in a dense integrated circuit doubles about every two years. 14 (MHz) http://www.ni.com/white-paper/6390/en
  • 16. Amdahl's law The maximum speedup of code with N threads when S portion of it is serial: - If all code is parallel (S = 0) then speedup equals to number of threads - If just 5% of code is serial the maximum possible speedup of code is 20 15
  • 17. Concurrency in Java 16 1996... 2003 2004 2005 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014... 1.0 5.0 6 7 8 java.lang.Thread java.util.concurrent (jsr166) jsr166x Project Lambda Fork/Join Framework (jsr166y)
  • 18. Let’s take numerical integration as the problem 17 Integration: The Rectangle Method A1 = f(x1)(b-a)/n
  • 29. What else? - RxJava (Project Reactor) - java.util.concurrent.Flow (Java 9) - ... 28
  • 30. List of references - Roman Elizarov’s talks on JMM and parallel computing - https://youtu.be/D8DXW7wlGDE - https://youtu.be/hxIRyqHRnjE - Andrey Rodionov, “From Java Threads to Lambdas”: https://youtu.be/W82D9eUn6q8 - Aleksey Shipilëv, “ForkJoinPool in Java 8”: https://youtu.be/t0dGLFtRR9c - Manning, “The Well-Grounded Java Developer” - Wiki - Process vs Thread - https://en.wikipedia.org/wiki/Happened-before - https://en.wikipedia.org/wiki/Monitor_(synchronization) 29 Github repo with talk code sources - https://github.com/fastovezz/evolution-of-multithreaded