HBase HTablePool:正确的用法 [英] HBase HTablePool: correct usage

查看:201
本文介绍了HBase HTablePool:正确的用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HTablePool的正确使用模式是什么?我的意思是,假设我有一个用HTablePool实例初始化的DAO。此DAO是无状态会话Bean的成员实例,因此它在调用之间重用。



以下内容的正确用法是什么?

  private HTableInterface一张桌子; 
$ b $ public XYZDAO(final HTablePool pool)
{
this.aTable = pool.getTable(...);


public void doSomething(...)
{
aTable.get(...)
}

或者HTablePool应该像Datasource一样使用,因此更适合于像这样的用法

  private HTablePool datasource; 
$ b $ public XYZDAO(final HTablePool池)
{
this.datasource = pool;
}

public void doSomething(...)
{
HTableInterface aTable = datasource.getTable(...);
aTable.get(...);
Table.close();
}


解决方案

第二种方法是最好的,你应该使用 HTablePool ,因为它是数据源,因为 HTable class不是线程安全的。对 HTableInterface 关闭方法的调用会自动将表返回到池中。



请注意, HConnection 接口取代了较新HBase版本中不推荐使用的 HTablePool

What is the correct usage pattern of HTablePool? I mean, assume that I have my DAO which is initialised with an instance of HTablePool. This DAO is a member instance of a Stateless Session Bean so it is reused between invocations.

What is the correct usage beween the following?

private HTableInterface aTable;

public XYZDAO(final HTablePool pool)
{
    this.aTable = pool.getTable(...);
}

public void doSomething(...)
{
    aTable.get(...)
}

or HTablePool should be used like a Datasource and therefore is more appropriate a usage like this

private HTablePool datasource;

public XYZDAO(final HTablePool pool)
{
    this.datasource = pool;
}

public void doSomething(...)
{
    HTableInterface aTable = datasource.getTable(...);
    aTable.get(...);
    aTable.close();
}

解决方案

The second approach is the best, you should use HTablePool like it was a Datasource since the HTable class is not thread safe. A call to the close method of HTableInterface will automatically return the table to the pool.

Note that there is HConnection interface that replaces the deprecated HTablePool in newer HBase versions.

这篇关于HBase HTablePool:正确的用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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