Threads in Java: Processes, Runnable and Thread
A thread is an independent path of execution inside one process, and Java gives you several ways to start one.
Threads, synchronisation and concurrency utilities.
9 notes
A thread is an independent path of execution inside one process, and Java gives you several ways to start one.
A thread moves through six states, and knowing which one it is in is the first step in diagnosing any hang.
synchronized gives mutual exclusion and visibility. volatile gives visibility only, and knowing the difference prevents most concurrency bugs.
Explicit locks offer timeouts, fairness and multiple conditions, and the atomic classes give lock free updates for single variables.
The two failures that define concurrency: results that depend on timing, and threads that wait for each other forever.
An executor separates submitting work from running it, so threads are reused instead of created per task.
A Future is a placeholder for a result that is not ready yet. CompletableFuture adds composition, so results can be chained without blocking.
Purpose built collections for shared access, which are both safer and far faster than wrapping an ordinary one in a lock.
The rules that decide when a write by one thread becomes visible to another, expressed as the happens-before relationship.