都说使用 池可以 提高效率, 提前new好的
private static HTablePool hTablePool;
早起代码是这样的
HTableInterface[] tables = new HTableInterface[10];
for (int i = 0; i < 10; i++) {
tables[i] = hTablePool.getTable(Bytes.toBytes( "a2" ));
}
for (HTableInterface table : tables) {
try {
table.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
HTableInterface table = hTablePool.getTable(Bytes.toBytes("a2"));
但是发现一个问题, 就是 可以在 一些 main(String[] args) 这种代码里面跑,正常拿到 table,在web项目中 却拿不到
创建起来 更简单, 更实用了
//--------------------------------------上面的代码后期发现无效了。 使用了新的 连接池方式
private static HConnection conn = null;
conn = HConnectionManager.createConnection(conf);
HTableInterface table = getTable(tableName);