I have a main Thread which calls an assertion. Inside the assertion there is another method which is being called and that method uses latch.await() . Now the Main thread dosen't wait for the assertion to be completed and moves forward in the program. Is this the expected behaviour and does that mean the parent method can continue execution if a method it has called is using latch.await ?
Asked
Active
Viewed 64 times
0

EJoshuaS - Stand with Ukraine
- 11,977
- 56
- 49
- 78

Dhruv Aggarwal
- 43
- 7
-
Could you post some code so I can reproduce the thing? – akuzminykh Jul 08 '20 at 18:25
-
Your main thread must call, CountDownLatch.await() method immediately after starting other threads. The execution will stop on await() method till the time, other threads complete their execution. – Amit kumar Jul 08 '20 at 18:41
-
Please post some code. And, are assertions enabled when running Java ? Usually you need the `-ea` flag – Daniele Jul 08 '20 at 20:49
-
Yes Amit , the error i was expecting was not caused by latch apparently and it did run synchronously . thanks . – Dhruv Aggarwal Jul 09 '20 at 13:09
1 Answers
0
The Execution did stop on the main thread until the count of latch went down to zero. And only then the rest of the program started to execute synchrounously.

Dhruv Aggarwal
- 43
- 7