curator-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Henrik Nordvik <>
Subject LeaderSelector Executor
Date Wed, 28 Aug 2013 14:44:55 GMT

The LeaderSelector has a constructor which takes in ThreadFactory and
Executor as parameters. The "default" constructor uses
I tried using my own ThreadPool with multiple threads, because I thought
that was they way of using multiple leaders.
When I did that, to my surprise, it started multiple leaders per path.
After reading the code it makes sense, it only guarantees that you are the
leader when submitting the thread to the executor.

It seems to me like using anything other than sameThreadExecutor makes
little sense.
When would you want to use it?

Example snippet:
    LeaderSelectorListener listener = new MyLeaderSelectorListener("1");
    ExecutorService executorPool = Executors.newFixedThreadPool(20);
    LeaderSelector leaderSelector = new LeaderSelector(client, path,
threadFactory, executorPool, listener);
    // MyLeaderSelectorListener.takeLeadership is called multiple times
here, even though it is in a sleep-loop.

Henrik Nordvik

View raw message