1. 创建 hbase 连接池
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.hbase.client.{Connection, ConnectionFactory}
import org.apache.hadoop.hbase.HBaseConfiguration
import org.slf4j.{Logger, LoggerFactory}
object HbaseConnectionPool {
private var conn: Connection = _
private var index: Int = _
private val logger: Logger = LoggerFactory.getLogger(this.getClass)
def getConnection: Connection = {
if (conn == null) {
this.synchronized {
if (conn == null) {
createConnection()
}
}
}
conn
}
private def createConnection(): Unit = {
index += 1
logger.warn(s"------------hbase connection created for the ${index} time ---------------")
val hbaseConf: Configuration = HBaseConfiguration.create()
hbaseConf.set("hbase.zookeeper.quorum", "hbase01:2181")
hbaseConf.set("zookeeper.znode.parent", "/hbase")
//hbaseConf.set("hbase.zookeeper.property.clientPort", "2181")
conn = ConnectionFactory.createConnection(hbaseConf)
}
}
https://blog.csdn.net/ycf921244819/article/details/81706119