In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
How to carry out concurrent tool class CountDownLatch and CyclicBarrier analysis, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
CountDownLatch
The basic process is that a thread waits for another thread to finish its work before executing. Enhanced join
Class, await is used to wait, and countDown (in the thread) is used to subtract one.
It is up to the initialization thread to decide whether to let it go.
Let's demonstrate the basic use of CountDownLatch in code:
Public class UserCountDownLatch {static CountDownLatch latch = new CountDownLatch (6); / / initialize thread private static class InitThread implements Runnable {@ Override public void run () {System.out.println ("Thread_" + Thread.currentThread (). GetId () + "ready init work..."); latch.countDown (); / / initialize thread finished working. Deduct once}} public static void main (String [] args) throws InterruptedException {/ / separate initialization thread. Initialization is divided into 2 steps, and new Thread (new Runnable ()) {@ Override public void run () {try {Thread.sleep (1000) is deducted twice. System.out.println ("Thread_" + Thread.currentThread (). GetId () + "ready init work step lst."); latch.countDown (); / / deduction of System.out.println ("begin step 2nd.") for each step completed; Thread.sleep (1000) System.out.println ("Thread_" + Thread.currentThread (). GetId () + "ready init work step 2nd."); latch.countDown (); / / deduction for each step completed} catch (InterruptedException e) {/ / TODO Auto-generated catch block e.printStackTrace ();}
}}). Start (); for (int item0)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.