Section 23.9 (Advanced) Producer/Consumer Relationship: The Lock and Condition Interfaces

• The Lock and Condition interfaces (p. 1002) give programmers more precise control over thread synchronization, but are more complicated to use.

• Any object can contain a reference to an object that implements the Lock interface (of package java.util.concurrent.locks). A thread calls a Lock’s lock method (p. 1002) to acquire the lock. Once a Lock has been obtained by one thread, the Lock will not allow another thread to obtain it until the first thread releases it (by calling the Lock’s unlock method; p. 1002).

• If several threads are trying to call method lock on the same Lock object at the same time, only one thread can obtain the lock—the others are ...

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.