How to make a Java thread wait for another thread’s output?

Use a CountDownLatch with a counter of 1.

CountDownLatch latch = new CountDownLatch(1);

Now in the app thread do-

latch.await();

In the db thread, after you are done, do –

latch.countDown();

Leave a Comment