---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 21 Edition"
java_version: 21
chapter: "Chapter 17. Threads and Locks"
section: "17"
heading: "Chapter 17. Threads and Locks"
source: https://docs.oracle.com/javase/specs/jls/se21/html/jls-17.html
id: "17"
url: https://jvm.obfuscated.software/jls/se21/17.html
raw: https://jvm.obfuscated.software/jls/se21/17.md
---

# Chapter 17. Threads and Locks

While most of the discussion in the preceding chapters is concerned only with the behavior of code as executed a single statement or expression at a time, that is, by a single *thread*, the Java Virtual Machine can support many threads of execution at once. These threads independently execute code that operates on values and objects residing in a shared main memory. Threads may be supported by having many hardware processors, by time-slicing a single hardware processor, or by time-slicing many hardware processors.

Threads are represented by the `Thread` class. The only way for a user to create a thread is to create an object of this class; each thread is associated with such an object. A thread will start when the `start()` method is invoked on the corresponding `Thread` object.

The behavior of threads, particularly when not correctly synchronized, can be confusing and counterintuitive. This chapter describes the semantics of multithreaded programs; it includes rules for which values may be seen by a read of shared memory that is updated by multiple threads. As the specification is similar to the *memory models* for different hardware architectures, these semantics are known as the *Java programming language memory model*. When no confusion can arise, we will simply refer to these rules as "the memory model".

These semantics do not prescribe how a multithreaded program should be executed. Rather, they describe the behaviors that multithreaded programs are allowed to exhibit. Any execution strategy that generates only allowed behaviors is an acceptable execution strategy.

**Sections:**

- [17.1. Synchronization](17.1.md)
- [17.2. Wait Sets and Notification](17.2.md)
- [17.3. Sleep and Yield](17.3.md)
- [17.4. Memory Model](17.4.md)
- [17.5. final Field Semantics](17.5.md)
- [17.6. Word Tearing](17.6.md)
- [17.7. Non-Atomic Treatment of double and long](17.7.md)
