It is a common idiom to have a single Zookeeper instance.  One reason for
this is that it can be hard to keep track of which instance has which
watches if you have lots of them around.

Instantiating several Zookeeper structures and then discarding them also
eliminates the utility of ephemeral philes.

Watches and ephemerals are two of the key characteristics of ZK, so they are
quite a loss.

That said, keeping a single zookeeper as a static in a single class isn't
such a strange thing to do, especially if you can't imagine closing the ZK
instance.  That gives you some scope but can keep the existence and use of
ZK a secret.

You do have to worry a bit about how to initialize the ZK.  For that reason
and for mocking purposes, it is pretty good practice to always inject the ZK
instance into your classes a la spring.

On Fri, Jun 5, 2009 at 8:56 PM, Grant Ingersoll <gsing...@apache.org> wrote:

> What's the overhead of connecting to a Server?  In other words, if I'm in a
> multi-threaded web-app server environment, should I cache my ZooKeeper
> instance and set a larger timeout value or should I just construct them as I
> need them?
>
>
>


-- 
Ted Dunning, CTO
DeepDyve

Reply via email to