Thread concurrency in java

Sanjay Singh
1 min readSep 22, 2021

--

1- CountDownLatch
2-CyclicBarrier
3- Phaser
4-Exchanger
5-Semaphore
6-SynchronousQueue

1-CountDownLatch- it was added to the Java 5 concurrency package.

It allows one or more threads to wait until a set of operations being performed in other threads are completed

C:\Users\sanjsingh>javap java.util.concurrent.CountDownLatch
public class java.util.concurrent.CountDownLatch {
public java.util.concurrent.CountDownLatch(int);
public void await() throws java.lang.InterruptedException;
public boolean await(long, java.util.concurrent.TimeUnit) throws java.lang.InterruptedException;
public void countDown();
public long getCount();
public java.lang.String toString();
}

Modifier and Type Method and Description
void await()
Causes the current thread to wait until the latch has counted down to zero, unless the thread is interrupted.

boolean await(long timeout, TimeUnit unit)
Causes the current thread to wait until the latch has counted down to zero, unless the thread is interrupted, or the specified waiting time elapses.

void countDown()
Decrements the count of the latch, releasing all waiting threads if the count reaches zero.

long getCount()
Returns the current count.

String toString()
Returns a string identifying this latch, as well as its state.

--

--

Sanjay Singh
Sanjay Singh

Written by Sanjay Singh

Java, Spring Boot & Microservices developer Sharing knowledge, tutorials & coding tips on my Medium page. Follow me for insights & see story list section

No responses yet