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
2
votes
1 answer

Java strange graphics blinking in while lock.await()

i have here a strange behaviour of my graphical user interface. At first here a piece of code: /** * */ @Override protected Void doInBackground() throws Exception { final ModelGameState actualGameState = controller.getActualGameState(); …
Mulgard
  • 9,877
  • 34
  • 129
  • 232
2
votes
1 answer

How to show a splash-screen, load datas in the background, and hide the splash-screen after that?

I'm designing a simple JavaFX form. First, I load the JavaFX environment (and wait for it to finish), with something like this : final CountDownLatch latch_l = new CountDownLatch(1); try { // init the JavaFX environment …
adrien.pain
  • 443
  • 2
  • 11
  • 18
2
votes
2 answers

Android CountDownLatch.await() freezes UI prematurely

So I am running some threads with a CountDownLatch. My problem is that when I call latch.await() the UI seems to hang and even UI commands that were called beforehand have no effect.…
jim
  • 8,670
  • 15
  • 78
  • 149
1
vote
1 answer

How to return value from Callable with CountDownLatch?

I want to use CountDownLatch with Callabe interface. I have Person class implements Callable interface which has CountDownLatch and Integer, Person#call() method returns integer value and within finally block countDown() method called. 2 Threads…
1
vote
1 answer

Executor service not waiting until all threads get completed to return the result

I am using an Executor service to execute set of parallel tasks and I need one done something after all the tasks get completed. But in my below implementation it is not happening as expected and it is not waiting till all done. Please refer to the…
CodeIntro
  • 191
  • 1
  • 1
  • 10
1
vote
1 answer

CountdownLatch await() is not waiting for last thread to end

I wrote a small peice of program to demonstrate the usage of CountDownLatch class in java. But, it not working as expected. I created 5 threads and assigned task to each thread. Now, each thread would wait for the start signal. Once the start signal…
kaddy
  • 109
  • 11
1
vote
1 answer

CountDownLatch to hold the parent thread

How can I hold the main thread until all 5 tasks(threads) have been completed? class ReadMessages { private final ExecutorService executorService = Executors.newFixedThreadPool(5); void readMessage(List msg ) { CountDownLatch…
1
vote
0 answers

Resetable CountDownLatch

I have a problem that I want to solve. I have one thread that must wait a number of a variable number of async threads to finish their execution finishes and after that, It must execute and again stay in the wait state until the other threads finish…
1
vote
1 answer

What's the inter-thread communication mechanism that can await and release underlying thread resource at the same time

I am looking for an inter-thread communication mechanism that can await and release underlying thread resource at the same time. In my example below, when the executorService is initialized with only 1 thread, the second task will be stuck because…
1
vote
0 answers

Thread.sleep vs CountDownLatch.await with timeout

I know that CountDownLatch is used to synchronize between processing in multiple threads. But my question is about using CountDownLatch for something it is not especially used for: waiting for some time before continuing executing instructions in…
Hamdi Douss
  • 1,033
  • 1
  • 8
  • 17
1
vote
1 answer

CountDownLatch in C++ using Boost Mutexes and Condition

I tried to implement CountDownLatch using boost mutexes and condition variable. Below is the code and would like to know if I need to add anything else. How can I unit test this code as well? template< class TypeVal > class AtomicCounter { …
Raja
  • 442
  • 5
  • 17
1
vote
2 answers

Updating two or more ProgressBar with countDownLatch

I'm learning multithreads with progressbar. I have got update without problems in the following simple code: public class Controller implements Initializable { @FXML private Button id_boton1; @FXML private Button id_boton2; @FXML private…
1
vote
1 answer

Firestore - using CountDownLatch to wait for task complete - hangs app

I have a big problem with CountDownLatch. I'm working on app which uses Firestore as database. I've created a file for managing the database, and I want to wait for for example writeSomethingToDb() function to complete. I found this example how to…
1
vote
1 answer

CountDownLatch makes the app stop

I'm working around with CountDownLatch and I need to send two JSON to send on sequence. I came out with this CountDownLatch countDownLatch = new CountDownLatch(1); try { sendAndgetEODID(countDownLatch); …
FroyoDevourer
  • 129
  • 11
1
vote
2 answers

CountdownLatch combine await(maxTime) and countdown()

I have several threads running for an almost infinite time and number of iteration. The iteration count being reset to 0 when a best solution has been found. A max number of iteration is set to prevent an infinite loop. I use a countdownlatch to…
Bastan
  • 1,009
  • 1
  • 8
  • 10