Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the distributed Barrier of Curator

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of "how to realize the distributed Barrier of Curator". The editor shows you the operation process through the actual case, and the operation method is simple, fast and practical. I hope that this article "how to realize the distributed Barrier of Curator" can help you solve the problem.

For distributed Barrier, just look at the code:

Package curator.barrier;import java.util.ArrayList;import java.util.List;import java.util.concurrent.ExecutorService;import java.util.concurrent.Executors;import org.apache.curator.RetryPolicy;import org.apache.curator.framework.CuratorFramework;import org.apache.curator.framework.CuratorFrameworkFactory;import org.apache.curator.framework.recipes.barriers.DistributedBarrier;import org.apache.curator.retry.ExponentialBackoffRetry Public class BarrierDemo {public static void main (String [] args) throws Exception {final List barriers = new ArrayList (3); ExecutorService service = Executors.newCachedThreadPool (); for (int I = 0; I < 3) Public void run +) {Runnable run = new Runnable () {public void run () {try {RetryPolicy retryPolicy = new ExponentialBackoffRetry ( one thousand, 3) Final CuratorFramework client = CuratorFrameworkFactory .builder () .connectString ("127.0.0.1purl 2181") .sessionTimeoutMs (5000) .connectionTimeoutMs (10000) .retryPolicy (retryPolicy) .namespace ("text") .build () Client.start (); DistributedBarrier barrier = new DistributedBarrier (client, "/ barrier"); barriers.add (barrier); barrier.setBarrier () / / set barrier System.out.println (": setBarrier..."); barrier.waitOnBarrier (); / / wait for other processes to remove barrier, after which all waitOnBarrier processes will be unblocked. System.err.println (": run ing...");} catch (Exception e) {}}; service.execute (run) } Thread.currentThread (). Sleep (5000); for (DistributedBarrier b: barriers) {b.removeBarrier ();} System.in.read ();}} that's all for "how to implement distributed Barrier for Curator". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report