我認爲這將很難找到爲Tomcat
製作的東西,我不認爲這樣的東西存在。大多數人可能使用自定義類。話雖如此,你應該圍繞HTablePool
建立一個HBase
。
這裏的東西,你可以在你的項目中使用的例子:
public class HTableManager {
public static int HTABLE_POOL_SIZE = 15;
private static HTableManager instance;
private static HTablePool hTablePool;
/**
* Private Constructor
*/
private HTableManager() {
try {
Configuration config = HBaseConfiguration.create();
config.set("hbase.defaults.for.version.skip", "false");
hTablePool = new HTablePool(config, HTABLE_POOL_SIZE);
} catch (IOException ex) {
// Error handling
}
}
/**
* @return The HbaseTableManager instance
*/
public static HTableManager getInstance() {
if (instance == null) {
instance = new HTableManager();
}
return instance;
}
/**
* Method used to retrieve a HTable instance.
*
* @param tableName The table name
* @return The HTableInterface instance
* @throws IOException
*/
public synchronized HTableInterface getHTable(String tableName) throws IOException {
return hTablePool.getTable(tableName);
}
}
然後你就可以使用它像這樣:
HTableManager hTableManager = htableManager.getInstance();
HTableInterface hTable = hTableManager.getHTable("yourTableName");
...
// Work with the hTable instance
...
// A call to the close method returns it to the pool
hTable.close();
而且,這裏我cant't找到一個理由,爲什麼close方法reutrns表中池,請參見:http://stackoverflow.com/questions/12190826/hbase-htablepool-correct-usage/17712233#17712233 – seb
閱讀的javadoc http://hbase.apache.org/apidocs /org/apache/hadoop/hbase/client/HTablePool.html –