Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to realize the distributed Barrier of Curator

Shulou Source: shulou.com Published: 2022-05-31 12:22:23 09月30日 Update

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.

Tags: Distributed knowledge industry process different practical code content practicality practice articles methods more cases knowledge points articles information channels processes questions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Redmi Apple Shulou Tech Info Linux