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

Countdown latch does not get decremented within DeliverCallback

I am trying to consume a message from a RabbitMQ channel using Java code. I invoke the myAction() method two times, and it works as expected only on the first one. private Channel receiveChannel=//...; String myAction() { var wrapper = new…
João Matos
  • 6,102
  • 5
  • 41
  • 76
0
votes
1 answer

unit testing Android function with handler

I'm working with unit testing for the first time and I'm lost with some specific cases. Despite reading a lot I'm confused about how to test a function like this in Android: void myFunction() { MyThread myThread = new MyThread(); …
Wonton
  • 1,033
  • 16
  • 33
0
votes
0 answers

Why the thread in the thread pool can't get be executed?

private static void calculateSum1() throws InterruptedException, ExecutionException { CountDownLatch latch = new CountDownLatch(3); int[] a = {1, 2, 3, 4, 5, 7}; int[] b = {8, 9, 10, 11, 12, 13}; int[] c = {14, 15,…
Aaron
  • 43
  • 7
0
votes
0 answers

Java CountDownLatch wait for async callback

First of all, I'm a complete newbie in Java. What I want to achieve is wait for async results before I return them. MainActivity.java: ... private SendTransport.Listener sendTransportListener = new SendTransport.Listener() { @Override …
Footniko
  • 2,682
  • 2
  • 27
  • 36
0
votes
1 answer

Pause/Continue in Pomodoro Timer project

I am building a pomodoro tracker in order to practice a little bit of JavaScript. It's been a while since I started this project. After this particulary problem which is implement a pause/continue functionality I abandoned the project. I really got…
0
votes
2 answers

Has JVM capability to kill threads because of resource constraint?

I have created priority based threads ex- Thread Priority T1 P1 T2 P1 T3 P2 T4 P2 I am using java.util.concurrent.CountDownLatch for all threads with same priority to execute simultaneously first then proceed with the next…
Harsh Vardhan
  • 111
  • 1
  • 4
0
votes
1 answer

RocketMQ Consumer await for result callback

I am using RocketMQ and want to get Message from Queue every new request @Service public class GetMessageFromQueue extends BaseObject { @Resource private RocketMQTemplate rocketMQTemplate; @Value("${demo.rocketmq.topic}") private String…
user3611168
  • 335
  • 1
  • 6
  • 27
0
votes
1 answer

Java - Can CountDownLatch.await() be reordered by the compiler

I have to invoke an operation on a different system. The other system is highly concurrent and distributed. Therefore I integrate it over a MessageBus. One implementation is required to let the caller wait until the result got received on the bus or…
Flova
  • 65
  • 6
0
votes
2 answers

Using AtomicInteger and CountDownLatch to generate one instance

I have a class which I want to have only one instance. However, I don't want multiple threads to call getInstance(). So I have coded it in the following way public class SomeService implements Provider{ private…
ha9u63a7
  • 6,233
  • 16
  • 73
  • 108
0
votes
1 answer

Java synchronization: multiple CountDownLatch

Following situation: Thread A starts Thread B and should wait until Thread B has done its job. Thread B could start a new Thread C. If it is the case Thread A should wait for Thread B and Thread C. I could implement it using two CountDownLatch, but…
Neo
  • 1,337
  • 4
  • 21
  • 50
0
votes
1 answer

CountDownLatch freezes thread on Android

I have a method, where I would like to check the validity of my token through an API call with Retrofit and I want to wait for the result. I thought to use CountDownLatch but it seems countDownLatch.await() locks the thread and nothing happens, the…
nagym08
  • 55
  • 8
0
votes
0 answers

Pthreads, how to prevent deadlock in a countdown latch

I'm working on implementing a countdown latch in C based on pthreads. I'm not sure why but the await function (which should simply block the threads until the count is zero) is giving me deadlock. gdb says all my threads are exiting. I'm not sure…
Kenneth Clarke
  • 119
  • 1
  • 1
  • 6
0
votes
0 answers

Countdownlatch hangs or terminates with no exception

I am working on java fxml where i take 2 inputs and use them to run a script. I pause at execution points of the script My problem is when i provide only 1 input (ex 1 2 add 3 equal)the code runs fine but when I am providing 2 inputs (ex 1 2 add…
0
votes
1 answer

CountDownLatch don't stop on counting to zero

I have a sample of code which I expect to print values. As I think after in run method after countDownLatch.countDown(); is called CountDownLatch should reach zero and main method should terminate, but it's not happening. Am I missing…
Artem Vlasenko
  • 115
  • 1
  • 1
  • 7
0
votes
2 answers

guava ThreadPool+CountDownLatch encounters IllegalMonitorStateException

I was trying to test guava concurrent package, as below. I expect that the created thread pool will execute the "Runnable" class instance and then wait for termination. import com.google.common.util.concurrent.ThreadFactoryBuilder; import…
Hind Forsum
  • 9,717
  • 13
  • 63
  • 119