Sychronizers Flashcards
High-level abstractions for synchronizing activities of two or more threads are known is?
Synchronizers
List the sychronizers provided in the java.util.concurrent library?
Semaphore, Phaser, CountDownLatch, and Exchanger, CyclicBarrier
Explain Semaphore?
A semaphore controls access to shared resources. A semaphore maintains a counter to specify the number of resources that the semaphore controls.
Example: ATM
A synchronizer that controls access to a fixed number of shared resources is?
Example controlling access to two ATM machines.
Semaphrore.
Explain CountDownLatch
This synchronizer allows one or more threads to wait for a countdown to complete.
Example: On your mark, get set, go!
What synchronizer allows one or more threads to wait for a countdown to complete.
5,4,3,2,1 go!
CountDownLatch
Explain Exchanger
The Exchanger class is meant for exchanging data between two threads. What Exchanger does is something very simple: it waits until both the threads have called the exchange() method.
What synchronizer is meant for exchanging data between two threads.
Exchanger
Explain CyclicBarrier
The CyclicBarrier is used to suspend treads until a predefined execution point is reached.
Wait for four players to arrive.
What synchronizer waits for a fixed number of threads to be waiting before starting execution.
CyclicBarrier
Explain Phaser
Phaser is a useful feature when few independent threads have to work in phases to complete a task.