A CountDownLatch is a synchronizer which allows one thread to wait for one or more threads before starts processing.
A good application of CountDownLatch is in Java server-side applications where a thread cannot start execution before all the required services are started.
A good application of CountDownLatch is in Java server-side applications where a thread cannot start execution before all the required services are started.
Working
A CountDownLatch is initialized with a given count which is the number of threads it should wait for. This count is decremented by calling countDown() method by the threads once they are finished execution. As soon as the count reaches to zero, the waiting task starts running.
Code Example
Let us say we require three services, LoginService, DatabaseService and CloudService to be started and ready before the application can start handling requests.
Output
Cloud Service is up! Login Service is up! Database Service is up! All services are up. Now the waiting thread can start execution.Here, we can see that the main thread is waiting for all the three services to start before starting its own execution. Once all the services (threads) are started, it can perform its own execution.
Conclusion
Congratulations!! 🙋 today we discussed CountDownLatch with an example. I hope you enjoyed this post.
3-reel and 3-reel Baccarat, Poker, Craps, Deuces, Poker
ReplyDelete3-reel and 3-reel Baccarat, Poker, Craps, Deuces, 바카라 Poker and Craps: All Card 메리트카지노 Games, Slots, Live Poker, Table Games, Video Poker. The Game was launched in 2012, and the 2nd gioco digitale