Sychronizers Flashcards

1
Q

High-level abstractions for synchronizing activities of two or more threads are known is?

A

Synchronizers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

List the sychronizers provided in the java.util.concurrent library?

A

Semaphore, Phaser, CountDownLatch, and Exchanger, CyclicBarrier

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Explain Semaphore?

A

A semaphore controls access to shared resources. A semaphore maintains a counter to specify the number of resources that the semaphore controls.
Example: ATM

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

A synchronizer that controls access to a fixed number of shared resources is?
Example controlling access to two ATM machines.

A

Semaphrore.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Explain CountDownLatch

A

This synchronizer allows one or more threads to wait for a countdown to complete.
Example: On your mark, get set, go!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What synchronizer allows one or more threads to wait for a countdown to complete.
5,4,3,2,1 go!

A

CountDownLatch

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Explain Exchanger

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What synchronizer is meant for exchanging data between two threads.

A

Exchanger

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Explain CyclicBarrier

A

The CyclicBarrier is used to suspend treads until a predefined execution point is reached.
Wait for four players to arrive.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What synchronizer waits for a fixed number of threads to be waiting before starting execution.

A

CyclicBarrier

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Explain Phaser

A

Phaser is a useful feature when few independent threads have to work in phases to complete a task.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly