Java provides thesynchronizedKeyword forsynchronizing thread access to criticalsections. Because it can difficult to correctly writesynchronizedcode that ' s based onsynchronized, high-Level Synchronizers is included in the concurrency utilities. A countdown latch causes one or more threads to wait at a "gate" until Anotherthread opens ThisGate, at which point these other threads canContinue. It consists of acount and operations for"causing a thread to wait until the count reaches zero" and "decrementing the count." A cyclic barrier lets a set of threads wait forEach of the other to reach a common barrierpoint. The barrier is cyclic because it can being reused after the waiting threads is released. This synchronizer was useful in applications involving a fixed-size Party of threads Thatmust occasionally wait forEach of the other . An exchanger provides a synchronization point where threads can swap objects. Each thread presents some object in entry to the exchanger ' s Exchange () method,matches with a partner thread, and receives Its partner ' s object onreturn. A semaphore maintains a set of permits forRestricting the number of threads thatcan access a limited resource. A thread attempting to acquire a permit when no permitsare available blocks until some other thread releases a permit. A phaser is a more flexible cyclic barrier. Like a cyclic barrier, a phaser lets a group ofthreads wait on a barrier; These threadsContinueAfter the last thread arrives. A phaser alsooffers the equivalent of a barrier action. Unlike a cyclic barrier, which coordinates a fixednumber of threads, a phaser can coordinate a variable number of threads, which can registerat any time. To implement ThisCapability, a phaser uses phases and phase numbers.
Java New synchronized