聊聊curator recipes的LeaderLatch
序 本文主要研究一下curator recipes的LeaderLatch 实例 @Test public void testCuratorLeaderLatch() throws Exception { CuratorFramework client = CuratorFrameworkFactory.newClient("localhost:2181", new ExponentialBackoffRetry(1000, 3)); client.start(); String leaderLockPath = "/leader-lock2"; List<LeaderLatch> latchList = IntStream.rangeClosed(1,10) .parallel() .mapToObj(i -> new LeaderLatch(client,leaderLockPath,"client"+i)) .collect(Collectors.toList()); latchList.parallelStream() .forEach(latch -> { try { latch.start(); } catch (Exception e) { e.printStackTrace(); } }); TimeUnit.SECONDS.sleep(5); Iterator