Skip to content

HbaseConnectionPool

VictorZeng edited this page May 12, 2016 · 4 revisions

Use the HbaseConnectionPool need instantiate PoolConfig and Properties

For example, the following

		/* poolConfig */
		PoolConfig config = new PoolConfig();
		config.setMaxTotal(20);
		config.setMaxIdle(5);
		config.setMaxWaitMillis(1000);
		config.setTestOnBorrow(true);
		
		/* properties */
		Properties props = new Properties();
		props.setProperty("hbase.zookeeper.quorum", "localhost");
		props.setProperty("hbase.zookeeper.property.clientPort", "2181");
		props.setProperty("hbase.master", "localhost:60000");
		props.setProperty("hbase.rootdir", "hdfs://localhost:9000/hbase");
		
		/* connection pool */
		HbaseConnectionPool pool = new HbaseConnectionPool(config, props);

		/* pool getConnection */
		Connection conn = pool.getConnection();

		/* conn getTable */
		Table table = conn.getTable(TableName.valueOf("TableTest"));

		...

		/* table close */
		table.close();
		
		/* pool returnConnection */
		pool.returnConnection(conn);

More configs see the Configuration wiki.