Synchronizers

The java.util.concurrent package contains several classes that help manage a set of collaborating threads—see Table 1-3. These mechanisms have “canned functionality” for common rendezvous patterns between threads. If you have a set of collaborating threads that follows one of these behavior patterns, you should simply reuse the appropriate library class instead of trying to come up with a handcrafted collection of locks.

Table 1-3. Synchronizers
ClassWhat It DoesWhen To Use
CyclicBarrierAllows a set of threads to wait until a predefined count of them has reached a common barrier, and then optionally executes a barrier action.When a number of threads need to complete before their results can be used.
CountDownLatchAllows a set of threads ...

Get Core Java™ 2 Volume II - Advanced Features, Seventh 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.