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

Java concurrency - reset condition after leaving method

I am trying to figure out a solution to the following problem: public void signal(){ //resets condition and signals threads blocked below } public void getValue(){ waitOnCondition(); //block if a condition is not met. When signalled, all…
struggler
  • 31
  • 1
0
votes
2 answers

How do I make sure only one thread gets started

The situation is, I have to make sure only one RecoveryThread gets created when I try to getConnection and if it fails on getConnection on PrimaryData Source fails., the code I have is: public Connection getConnection() throws SQLException { …
Syed Siraj Uddin
  • 583
  • 1
  • 5
  • 13
0
votes
1 answer

How to implement "downloader files" in a method?

I have created a code to download multiple files showing a progressbar progress. This works perfectly, but now I want to deploy it to an external project (library itself) and I have problems. My intention is to call "download" and when the download…
ephramd
  • 561
  • 2
  • 15
  • 41
0
votes
1 answer

CountDownLatch throwing exception when trying to await()

I have a thread A which runs another thread B. Thread A implements a method "stopExec()" which tries to exit thread B cleanly - allowing it to finish some tasks. So my stopExec method looks something like this: private CountDownLatch lock; public…
hpet
  • 299
  • 2
  • 14
0
votes
1 answer

Is it ok to use static Latch or Semaphore?

I have some classes that implement Runnable interface. Each of them is is executed via the separate SingleThreadExecutor. I cannot modify the execution routine, I can just provide different Runnables for it. I need to make some operations with…
KutaBeach
  • 1,445
  • 21
  • 43
0
votes
2 answers

Wait for Swing Interface to close before proceeding

I've been searching near and far for a solution to my question but I am having difficulty even defining my search terms. I have a method that creates a Swing GUI using invokeLater where the user completes some task. Once the task is completed, the…
jsatria
  • 1
  • 3
0
votes
1 answer

CyclicBarrier and CountDownLatch?

What is the difference between CyclicBarrier and CountDownLatch? I thnik there is subtle difference, as both looks same. Please let me know if I am wrong and also explain same.
user900721
  • 1,417
  • 4
  • 17
  • 29
-1
votes
3 answers

How to start 1K threads and continously run the threads on the same task when they complete

If I create 1K threads and launch them at the same time using a latch, once the threads complete my process ends. What I want to do is, as the thread ends, start up another thread to work on the same task (or somehow get the same thread to continue…
codecompleting
  • 9,251
  • 13
  • 61
  • 102
-1
votes
3 answers

jQuery Countdown plugin and AJAX

I'm using jQuery Countdown plugin to implement a Countdown and call a webservice when timer expires. The problem is that I'm using AJAX on the page, and have to re-setup the Countdown on every AJAX request like so: var prm =…
roman m
  • 26,012
  • 31
  • 101
  • 133
-1
votes
2 answers

Countdownlatch get count returns inconsistent values

I have developed a sample java program to understand countdownlatch & initialized the countdownlatch with count 4. I expected that after countDown method, the getCount() would return the remaining count for the countdownlatch. But, in the following…
-1
votes
2 answers

Do threads waiting on CountDownLatch execute in fifo order?

Say i have a count down latch like with count=1 Suppose i have two threads(T1, T2) waiting on latch. Say T1 came first and called latch.await() and later came T2 When latch is count down is there is guarantee that T1 will be executed first and…
samuel koduri
  • 389
  • 2
  • 4
  • 9
-1
votes
1 answer

ExecutorService does not block till the thread finishe

i have a class FeatOrientation and in that class in its constructor i perform two operations each one in a separate thread and i am using CountDownLatch so that, when gaussThread finishes the laplaceThread startes. and in the main class that has the…
Amrmsmb
  • 1
  • 27
  • 104
  • 226
-1
votes
2 answers

Why the overall performance of application degrades if I do null checks on the maps?

Below is my class which uses CountDownLatch to make sure reads are not happening on the primary, secondary and tertiary maps for the first time whenever writes are happening on those maps. public class ClientData { public static class Mappings…
john
  • 11,311
  • 40
  • 131
  • 251
-1
votes
2 answers

How to prevents read from happening whenever I am doing a write?

I am trying to implement lock by which I don't want to have reads from happening whenever I am doing a write. Below is my ClientData class in which I am using CountDownLatch - public class ClientData { private static final…
AKIWEB
  • 19,008
  • 67
  • 180
  • 294
-3
votes
1 answer

Why is my second thread not running?

I have the following program where I would like to have 3 threads the smokers wait for the agent. I'm trying to use the CountDown latch to implement this. public void runThreads(){ int numofTests; Scanner in = new…
Austin Davis
  • 3,516
  • 10
  • 27
  • 47
1 2 3
11
12