You have to be careful there of race conditions.  ZK's slightly surprising
API makes it pretty easy to get this right, however.

The correct way to do what you suggest is to read the list of children in
the locks directory and put a watch on the directory at the same time.  If
the number of locks equals the number of resources, you wait.  If it is
less, you can randomly pick one of the apparently unlocked resources at
random.  If you fail, start again by checking the number of resources.

On Tue, Feb 23, 2010 at 9:09 PM, Martin Waite <>wrote:

> I guess another optimisation might be to count the number of locks held
> first:  if the count equals the number of resources, try again later.  But
> I
> suppose that might require a sync call first to ensure that zk instance my
> client is connected to is up to date.

Ted Dunning, CTO

Reply via email to