Skip to content

Commit cb957c9

Browse files
authored
Update interviewQuestions.md
1 parent 384b6c2 commit cb957c9

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

interviewQuestions.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ stop(executor);
100100
- sleep need try catch interruption
101101

102102
#### 12. What is difference between CyclicBarriar and CountdownLatch in Java ?
103-
One difference is that you can reuse CyclicBarrier once barrier is broken but you can not reuse CountdownLatch.
103+
- CountdownLatch: A synchronization aid that allows one or more threads to wait until a set of operations being performed in other threads completes.
104+
A CountDownLatch is initialized with a given count. The await methods block until the current count reaches zero due to invocations of the countDown() method, after which all waiting threads are released and any subsequent invocations of await return immediately. This is a one-shot phenomenon -- the count cannot be reset. If you need a version that resets the count, consider using a CyclicBarrier.
105+
106+
- One difference is that you can reuse CyclicBarrier once barrier is broken but you can not reuse CountdownLatch.
104107
Though both CyclicBarrier and CountDownLatch wait for number of threads on one or more events, main difference between them is that you can not re-use CountDownLatch once count reaches to zero, but you can reuse same CyclicBarrier even after barrier is broken.
105108

106109
#### 13. Difference between Runnable and Callable in Java?

0 commit comments

Comments
 (0)