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
HTablePoollike it was aDatasourcesince theHTableclass is not thread safe. A call to theclosemethod ofHTableInterfacewill automatically return the table to the pool.Note that there is
HConnectioninterface that replaces the deprecatedHTablePoolin newer HBase versions.