This presentation by Maksym Fastovets (Senior Software Engineer, Consultant, GlobalLogic, Kharkiv) was delivered at GlobalLogic Kharkiv Java Conference 2019 on June 9, 2019.
Maksym touched upon the Java development from Thread to CompletableFuture and introduced the Monitor concept and its implementation in Java. He also did not overlook Java tools supporting multithreading and asynchronous coding that exist aside from JDK.
Video: https://youtu.be/pLXQWbwneOw
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
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
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
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’s source code
- https://github.com/fastovezz/evolution-of-multithreaded