zookeeper-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominic Williams <thedwilli...@googlemail.com>
Subject Re: Modify ZooKeeper Java client to hold weak references to Watcher objects
Date Fri, 19 Mar 2010 10:11:59 GMT
Hi I can see some people might be assigning for example anonymous class
instances as watchers/handlers, and not keeping any references to them.

To avoid breaking existing use cases, two options:

1/ Add a useWeakReferences parameter to new constructor (sets default

2/ Add alternative methods, which take useWeakWatcherRef boolean.

Internally will be trivial to have both

private final Map<String, Set<Watcher>> dataWatches =
            new HashMap<String, Set<Watcher>>();

private final Map<String, WeakSet<Watcher>> dataWatchesWeak =
            new HashMap<String, WeakSet<Watcher>>();

On 18 March 2010 22:47, Ted Dunning <ted.dunning@gmail.com> wrote:

> This kind of sounds strange to me.
> My typical idiom is to create a watcher but not retain any references to it
> outside the client.  It sounds to me like your change will cause my
> watchers
> to be collected and deactivated when GC happens.
> On Thu, Mar 18, 2010 at 3:32 AM, Dominic Williams <
> thedwilliams@googlemail.com> wrote:
> >
> > The current ZooKeeper client holds strong references to Watcher objects.
> I
> > want to change the client so it only holds weak references. Feedback
> > please.

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message