这是对HBase访问的简单封装,主要是Spark executor上使用,就没有注意多线程安全了。若有需要自己优化。
直接贴代码:
/** * HBase Utility class, HBase Design document see: <br/> * Attention: put/get/del is not thread safe due to use HBase Table interface. * * @author adore.chen * @date 2020-04-30 */ @Slf4j public class HBaseUtil { private static final Configuration hbaseConf = HBaseConfiguration.create(); static { hbaseConf.set(ZOOKEEPER_QUORUM, Config.getString(ZOOKEEPER_QUORUM)); hbaseConf.set(ZOOKEEPER_CLIENT_PORT, Config.getString(ZOOKEEPER_CLIENT_PORT)); } /** * lazy singleton pattern for HBase Connection or Table interface. */ private static class Helper { static Connection CONNECT; static { try { // init connection CONNECT = ConnectionFactory.createConnection(hbaseConf); Runt