When CuratorFramework's methods start and close shoud be called?

安稳与你 提交于 2019-12-24 17:09:59

问题


According to documentation

CuratorFramework instances are fully thread-safe. You should share one CuratorFramework per ZooKeeper cluster in your application.

It also states that the method start should be called before any other operations can be performed. Should this method be called before every operation or calling it once after initialization is enough?


回答1:


Call start once after creating the CuratorFramework instance. So, the startup is:

  • Create the CuratorFramework via one of the factory methods
  • Call start() on the instance
  • Run your application using the single CuratorFramework instance as needed
  • At the end of your application, call close() on the instance

NOTE: I'm the main author of Curator




回答2:


The initial tests showed, that start should be called only once per created client. Calling it multiple times caused IllegalStateException.



来源:https://stackoverflow.com/questions/20384869/when-curatorframeworks-methods-start-and-close-shoud-be-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!