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

查看:27
本文介绍了应该在 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 实例后调用 start 一次.所以,启动是:

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

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

注意:我是 Curator 的主要作者

NOTE: I'm the main author of Curator

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

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