我认为很难找到适合的东西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();