CyclicBarrier, CountDownLatch and wait () What is the difference?
2. Answers
wait(): Object class method is provided that allows the current thread to stop executing, and release the resources associated with the conversion from a running thread state to wait state;
CyclicBarrier(int n, Runnable barrierAction): CyclicBarrier class constructor is used when n threads have reached the barrier, the following thread execution priority barrierAction, then other threads to execute, easy to handle more complex business scenario;
CountDownLatch(int count): Is the class constructor CountDownLatch, refers to half a thread execution is interrupted, wait for the end of the other n threads running in order to continue the thread of the code;