一、HBase连接池
注意:HBase2.1.2之后的版本,无需创建HBase线程池,HBase2.1.2提供的代码已经封装好,只需创建调用即可。
Connection conn = ConnectionFactory.createConnection(conf);
//conn在获取Table的时候,底层默认会从线程池中获取一个连接
Table table = conn.getTable(TableName.valueOf("s1"));
所以table在用完之后可以直接调用close方法即可,在程序关闭的时候调用conn的close方法即可。
查看源码最终可以追踪到这里:
org.apache.hadoop.hbase.client.ConnectionImplementation
默认会创建一个线程池,256个连接。
private ThreadPoolExecutor getBatchPool() {
if (batchPool == null) {
synchronized (this) {
if (batchPool == null) {
int threads = conf.getInt("hbase.hconnection.threads.max", 256);
this.batchPool = getThreadPool(threads, threads, "-shared", null);
this.cleanupPool = true;
}
}
}
return this.batchPool;
}