Abstract:
CuratorFramework client = CuratorFrameworkFactory.newClient("localhost:2181", new ExponentialBackoffRetry(1000, 3));
client.start();
InterProcessMutex lock = new InterProcessMutex(client, "/shared-lock");
try {
if (lock.acquire(10, TimeUnit.SECONDS)) {
}
} finally {
lock.release();
}
CuratorFramework client = CuratorFrameworkFactory.newClient("localhost:2181", new ExponentialBackoffRetry(1000, 3));
client.start();
DistributedQueue<String> queue = new DistributedQueue<>(client, "/task-queue");
queue.offer("task1".getBytes());
queue.offer("task2".getBytes());
queue.offer("task3".getBytes());
String task = queue.take();
System.out.println("Process task: " + task);
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>x.x.x</version>
</dependency>
CuratorFramework client = CuratorFrameworkFactory.newClient("localhost:2181", new ExponentialBackoffRetry(1000, 3));