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
2 answers

Unable to determine why CountDownLatch is not functioning when multiple runnable interfaces are implemented in anonymous classes inside a class

If I define a class Team and implement two runnable interfaces inside that class, I do not get to a point in the program where the tasks by team1 and team2 ends. However if I implement the runnable directly in the class as in WorkerOne, I get to…
Yogesh Ghimire
  • 432
  • 1
  • 8
  • 21
0
votes
2 answers

CountDownLatch : preserving the threading order on countDown reached

Is it possible to preserve the order of threading as they hit await when countDown is reached. If thread 1 calls await before thread 2, then they should be reschudeled in the same order. Does that even make any sense :) ?
Snicolas
  • 37,840
  • 15
  • 114
  • 173
0
votes
1 answer

Wait for external Thread to start

I use FileAlterationMonitor from Apache and I would like to know when it is done initializing. I call fileAlterationMonitor.start(); which starts a new thread and my program moves on, before fileAlterationMonitor is done initializing. I would like…
korsgaard
  • 84
  • 8
0
votes
0 answers

Android : CountDownLatch Doesn't work

Following is my class which uses a CountDownLatch and ExecutorService. I all startTest method from my activity. When I run this code CountdownLatch doesn't come out of wait. public class Test implements Tester.StartListener, Tester.StopListener,…
Akshay
  • 833
  • 2
  • 16
  • 34
0
votes
1 answer

dividing a huge file using threads

I have a text file that contains > 500 million lines and it is structured as follows: 54517. lat:53.533459; lon:8.8005426; path:c:\brem_5.xml; 54518. lat:53.037579; lon:8.800404; path:c:\brem_5.xml; 54519. lat:53.03358275; lon:8.610994;…
rmaik
  • 1,076
  • 3
  • 15
  • 48
0
votes
0 answers

How to return one object from a class implements Callable

I have a class that implements callable, and i want the callable class to return only one object of type Mat. I declared the Future list as follows: private static Future> fiConspFutureList = null; fiConspFutureList = new…
Amrmsmb
  • 1
  • 27
  • 104
  • 226
0
votes
2 answers

Mismatch of return datatype

i am facing a problem regrading specifying the return data type. I have the FOComp class which implements callabale, the call() method of the 'FOComp' returns data type List> as shown in the code of 'FOComp' class below. and the…
Amrmsmb
  • 1
  • 27
  • 104
  • 226
0
votes
2 answers

How to know if a latch finished its task

I have two threads with countDownLatch set to 1, so that, when the first threads finishes the second should starts. And what I want to do is, when the second finishes its task, I want to get the data computed from both threads to do some…
Amrmsmb
  • 1
  • 27
  • 104
  • 226
0
votes
3 answers

How to use the CountDownLatch for two different threads each of them has the same runnable class

How to use the CounDownLatch for two different threads each of them has the same runnable class?? i want FICS and fiCS_R7 to have the same runnable class FICS, but when fiCS_R3 finishes fiCS_R7 starts. how can I do that. Code: public…
Amrmsmb
  • 1
  • 27
  • 104
  • 226
0
votes
2 answers

Java CountDownLatch with Threads

I am looking to learn about using the Java CountDownLatch to control the execution of a thread. I have two classes. One is called Poller and the other is Referendum. The threads are created in the Referendum class and their run() methods are…
Son Goku
  • 21
  • 5
0
votes
1 answer

Java CountDownLatch used to wait for JFrame to dispose

I have referenced this previous question as well as other sources, but cannot get CountDownLatch to work correctly. Background: mainFrame creates new Frame called dataEntryFrame. When dataEntryFrame "Submit" button is clicked, record added to…
Brian
  • 203
  • 2
  • 3
  • 13
0
votes
1 answer

Using CountDownLatch & Object.wait inside recursive block hangs

Problem: While trying to retrieve values inside a recursive block in a phased manner, the execution gets hung. Description: CountDownLatch & Object.wait are used to achieve the phased manner access of value inside the recursive block. But, the…
bprasanna
  • 2,423
  • 3
  • 27
  • 39
0
votes
0 answers

Convert non-blocking android FusedProvider API to blocking

I am trying to use the non-blocking FusedLocationProvider API as a blocking one. Here's what I am doing (roughly): Start an AsyncTask In the background thread, connect to the PlayServices/FusedProvider API. There is a blocking method with a timeout…
0
votes
3 answers

UI Thread gets stuck even though I'm working on another

I have this code that on a click of a button a service will be started from a new thread and the service will start my TCP Client. The TCP client, once connected will send a count down event to inform the fragment to continue working. the code looks…
Yosi199
  • 1,745
  • 4
  • 22
  • 47
0
votes
1 answer

CountDownLatch used with two Parse queries?

I was making two Parse.com queries .. ABC.findInBackground(new FindCallback() { ... } DEF.findInBackground(new FindCallback() { ... } and I essentially tried doing this, CountDownLatch waitForBoth = new…
Fattie
  • 27,874
  • 70
  • 431
  • 719