当CuratorFramework的方法启动和关闭时应调用? [英] When CuratorFramework's methods start and close shoud be called?

查看:496
本文介绍了当CuratorFramework的方法启动和关闭时应调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据文档

CuratorFramework实例是完全线程安全的.你应该分享一个 您的应用程序中每个ZooKeeper群集的CuratorFramework.

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

它还指出,应该在执行任何其他操作之前调用方法 start .应该在每次操作之前调用此方法还是在初始化之后调用一次?

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?

推荐答案

在创建CuratorFramework实例后,调用一次启动.因此,启动是:

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

  • 通过一种工厂方法创建CuratorFramework
  • 在实例上调用start()
  • 根据需要使用单个CuratorFramework实例运行您的应用程序
  • 在应用程序结束时,在实例上调用close()

注意:我是策展人的主要作者

NOTE: I'm the main author of Curator

这篇关于当CuratorFramework的方法启动和关闭时应调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆