Questions tagged [countdownlatch]

A countdown latch is a synchronization primitive that allows one or more threads to wait until a certain number of operations are completed on other threads.

A countdown latch is a synchronization primitive that allows one or more threads to wait until a certain number of operations are completed on other threads.

The primitive keeps an internal counter initialized with the number of operations to complete. When a working thread signals the completion of an operation, the internal counter is decremented. When this counter reaches zero, the waiting threads are allowed to continue execution.

Resources

Documentation of Java's CountdownLatch class

166 questions
0
votes
1 answer

CountDownLatch blocking callbacks from other threads

I have to load a font with callbacks and set it as the theme typeface with a reflection method. And this has to be done before the setContentView() in onCreate() is called. I tried to use a CountDownLatch on the main thread as below to make it wait…
Jack
  • 5,354
  • 2
  • 29
  • 54
0
votes
1 answer

Java 8 Testing Concurrency

SO... I have this utility class that performs retries (to anything, theoretically) after the initial call has not returned after a given amount of time, and continually does so until any source returns data or until all are exhausted. This uses…
Lane
  • 685
  • 2
  • 10
  • 25
0
votes
2 answers

why can't Countdownlatch in java stops at given latch count?

import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; class Processor implements Runnable { private CountDownLatch latch; public Processor(CountDownLatch latch) { …
iramshiv
  • 3
  • 3
0
votes
0 answers

Building a highly scalable, failure tolerant flash sales backend

I have concert tickets to sell, 1.000.000 of them. They are very popular, and as soon as the order button goes live, I will have a very high load of people trying to get them. Lets say 10.000 requests in parallel as worst case. I want to sell at…
Michael Böckling
  • 7,341
  • 6
  • 55
  • 76
0
votes
1 answer

JUnit and Latches

// improving the description as requested // The code works fine as it is below. But if I move one assert(Latch) from testA to testB; the assertion fails. No matter how much delay I give it. Also I did this experiment: if I create a new latch and…
luide
  • 37
  • 6
0
votes
1 answer

Usecase of CountDownLatch where CyclicBarrier can't be used

For me the difference between CountDownLatch and CyclicBarrier is only that CyclicBarrier provides extra functionalities than CountDownLatch like you can execute a certain task when all threads would reach on a barrier point. You can find no of…
Indiver kumar
  • 15
  • 2
  • 8
0
votes
1 answer

CountDownLatch with a dynamic timeout

I am using a CountDownLatch to wait for N operations to complete before executing some code, whilst giving a timeout to make sure that the final code gets executed even if not all N operations are completed. i.e: CountDownLatch latch= new…
iddqd
  • 1,225
  • 2
  • 16
  • 34
0
votes
1 answer

CountDownLatch.await() suspending background threads

I'm working on an android app which at some point runs a service. That service runs a new thread for a time-consuming operation and waits for a countDownLatch to be zero. After that it runs a second thread for another time-consuming operation (that…
Miguel Lasa
  • 470
  • 1
  • 7
  • 19
0
votes
0 answers

RxJava Observable continue processing stream after error

Consider this example: while(currentObjectNumber < maximumObjectNumber){ maximumObjectNumber = getMaximumObjectNumber(); CountDownLatch countDownLatch = new CountDownLatch(maximumObjectNumber - currentObjectNumber); …
I. Kirilov
  • 281
  • 3
  • 12
0
votes
1 answer

On closing the main Swing window, the other thread on the EventQueue gets not created

I write Java SE 8 desktop application. It's got a Swing UI. Platform: Eclipse IDE Windows 10 OS Now when I close the main window, by pressing on the "X" on the top-right-corner, I have a listener to listen for such event. The listener right here: …
ucas
  • 417
  • 1
  • 11
  • 30
0
votes
1 answer

Android : AsyncTask not reaching onPostExecute

I am using AsyncTask to avoid networkonmainthreadexception on my Android Library Project, now what I want to do is to get the value to be returned to my variable and wait for it before executing the next line of code. I used CountDownLatch to do…
Aaron
  • 2,591
  • 4
  • 27
  • 45
0
votes
0 answers

Communication between two threads running on different JVMs on two different machines in java?

Currently, I am using Zookeeper for sharing configurations between different JVMs running on different nodes. In one of the node, the thread is waiting for some data to be written to specific zookeeper path and I have added watcher too to look out…
Mohini
  • 97
  • 10
0
votes
1 answer

how latch has no effect in javafx?

I encounter a problem in developing javafx, I find latch has no effect in JavaFx, for example, in the following code: public class JavafxLatchDemo1 extends Application { @Override public void start(Stage primaryStage) throws…
0
votes
1 answer

Java concurrency: Modifying latch/ThreadGroup to achieve Executor behaviour

This question is related to my homework assignment in Java concurrency topic. I have been tasked to spawn new threads and limit them by a given concurrencyFactor. That is, keep on dispatching new threads until number of active threads is less than…
qrius
  • 621
  • 2
  • 9
  • 22
0
votes
3 answers

What's the point of CountDownLatch in java?

CountDownLatch in java is a high-level synchronization utility which is used to prevent a particular thread to start processing until all threads are ready. But, Semaphore can totally do the same thing. So, what's the merit of CountDownLatch? One…
expoter
  • 1,622
  • 17
  • 34