Section 23.4 Thread Synchronization

• Thread synchronization (p. 968) coordinates access to shared mutable data by multiple concurrent threads.

• By synchronizing threads, you can ensure that each thread accessing a shared object excludes all other threads from doing so simultaneously—this is called mutual exclusion (p. 968).

• A common way to perform synchronization is to use Java’s built-in monitors. Every object has a monitor and a monitor lock (p. 968). The monitor ensures that its object’s monitor lock is held by a maximum of only one thread at any time, and thus can be used to enforce mutual exclusion.

• If an operation requires the executing thread to hold a lock while the operation is performed, a thread must acquire the lock (p. 968 ...

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.