countDownLatch
时间: 2023-11-11 13:23:29 浏览: 83
CountDownLatch is a synchronization tool in Java that allows one or more threads to wait for the completion of a set of operations performed by other threads. It is a type of barrier that blocks the progress of the calling thread until the count reaches zero.
The CountDownLatch class has a constructor that takes an integer value representing the number of times the countDown() method must be invoked before the waiting threads can proceed. The countDown() method decrements the count by one, and the await() method blocks the calling thread until the count reaches zero.
CountDownLatch is often used to coordinate the execution of multiple threads in a concurrent program. For example, a main thread can wait for several worker threads to complete their tasks before continuing with the execution of the program.
阅读全文