Hbase 的 htablepool的小記錄

都說使用 池可以 提高效率, 提前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);




發佈了55 篇原創文章 · 獲贊 3 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章