use getData() instead of exists() to avoid leaving unneeded watchers which is a type of resource leak
Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/91d65037 Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/91d65037 Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/91d65037 Branch: refs/heads/CURATOR-105 Commit: 91d65037bf28947b5b28b75ec83614bb70a3e12a Parents: 290186a Author: randgalt <randg...@apache.org> Authored: Fri May 23 07:47:56 2014 -0500 Committer: randgalt <randg...@apache.org> Committed: Fri May 23 07:47:56 2014 -0500 ---------------------------------------------------------------------- .../org/apache/curator/framework/recipes/leader/LeaderLatch.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/curator/blob/91d65037/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderLatch.java ---------------------------------------------------------------------- diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderLatch.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderLatch.java index ecdd903..88456af 100644 --- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderLatch.java +++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderLatch.java @@ -519,7 +519,8 @@ public class LeaderLatch implements Closeable } } }; - client.checkExists().usingWatcher(watcher).inBackground(callback).forPath(ZKPaths.makePath(latchPath, watchPath)); + // use getData() instead of exists() to avoid leaving unneeded watchers which is a type of resource leak + client.getData().usingWatcher(watcher).inBackground(callback).forPath(ZKPaths.makePath(latchPath, watchPath)); } }