Java Concurrency Tutorial

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:

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.

 

Basics

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.

Thread-safe designs
After looking at the main risks of sharing data, this post describes several class designs that can be shared safely between different threads.

Synchronization

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.