This Java concurrency tutorial consists of several posts that explain the main concepts of concurrency in Java. It starts with the basics with posts about the main concerns or risks of using non synchronised programs.
This tutorial consists on two main areas:
- Basic concepts about how concurrency works
- This section explains different synchronisation mechanisms
Therefore, each section concept links to an article explaining it with examples. In addition, each article contains examples based on source code you can check on Github.
Atomicity and race conditions
Atomicity is one of the main concerns in concurrent programs. This post shows the effects of executing compound actions in non-synchronized code.
Visibility between threads
Another of the risks of executing code concurrently. How values written by one thread can become visible to other threads accessing the same data.
After looking at the main risks of sharing data, this post describes several class designs that can be shared safely between different threads.
Locking – Intrinsic locks
Intrinsic locks are Java’s built-in mechanism for locking. It ensures that compound actions within a synchronized block are atomic and create a happens-before relationship.
Locking – Explicit locks
Explicit locks provide additional features to the Java synchronisation mechanism. Here, we take a look at the main implementations and how they work.