0

I would like to utilize zookeeper to create distributed lock. I have the Factory creating LockObject that allow to lock/unlock some value. Every LockObject created by the Factory uses the same org.apache.zookeeper.Zookeeper object.

Now, I would like to use this Factory, as EJB so the other services could use it. We can assume that multiple threads will be using same Zookeeper object simultaneously. What I'm dealing with is to restrict the number of connections that can be created from the application. Is there any kind of connection pool for zookeeper or is single org.apache.zookeeper.Zookeeper object appropriate for this problem?

Best, A

androdevo
  • 752
  • 1
  • 8
  • 17

1 Answers1

1

A single org.apache.zookeeeper.Zookeeper can be shared by multiple threads.

Rather than write your own code around zookeeper, look at the Curator libary.

sbridges
  • 24,960
  • 4
  • 64
  • 71
  • So you think it is good idea to use one Zookeeper instance with lets say 50 EJBs? – androdevo Nov 10 '12 at 17:52
  • The number of ejb's doesn't mean anything, it is the number of zookeeper operations per second that is meaningful. You will be fine doing hundreds of zookeeper operations per second with a single zookeeper instance. – sbridges Nov 10 '12 at 19:09
  • I was not sure and made few tests. There was a pool of threads performing the same job(locking/unlocking). First group shared the same Zookeeper, the other had dedicated one. The group with dedicated ZK per thread was 20-30% faster. – androdevo Nov 10 '12 at 19:23
  • Can you recommend some concept of maintaing single client in jee application? – androdevo Nov 11 '12 at 15:23
  • @androdevo what zookeeper connection pool do you use? – tianyapiaozi Apr 11 '14 at 02:09