FAQ Database Discussion Community


Using CountDownLatch & Object.wait inside recursive block hangs

java,recursion,concurrency,wait,countdownlatch
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 program hangs with following output: 2 < 16 3 < 16 4...

Java: is CountDownLatch threadsafe

java,thread-safety,countdownlatch
In the docs for CountDownLatch I see something like: public void run() { try { startSignal.await(); doWork(); doneSignal.countDown(); } catch (InterruptedException ex) {} // return; } Here startSignal and doneSignal are CountDownLatch objects. The docs don't mention anything about the class being thread-safe or not....

Usage of countDown latch in java

java,multithreading,countdownlatch
Am new to java programming and first time using countDown in java, My code snippet is, CountDownLatch latch=new CountDownLatch(rows*columns); //rows -2 , columns -3 for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { GUIView view = getView(1, 1); if(view...

How to get results from the CompletableFuture

java,multithreading,threadpool,executorservice,countdownlatch
each of "CompletableFuture.runAsync" mentioned in the code below does some calculations, an i want to get the results each time i call "CompletableFuture.runAsync". or in other words, i want each of "future0,future1,future2,future3" to contain the result of each call to "CompletableFuture.runAsync" respectively how can i do that. *Update: my requirements...

Mismatch of return datatype

java,multithreading,callable,countdownlatch
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<ArrayList<Mat>> as shown in the code of 'FOComp' class below. and the method 'getResults()' returns data of type ArrayList<Mat> as shown in...

how to know the exact time thread requires to finish

java,multithreading,executorservice,countdownlatch
I have two threads t1 and t2. Both of them make some calculations and i am tryin to block the main thread till t1 and t2 finish. I used .awaitTermination() as seen below, but the problem is, despit it is an if-statement, the .awaitTermination() goes in an infinite loop. please...