多线程创建connection连接hbase

public class Getconnection {
    //声明一个静态属性
    public static Connection connection = null;

    static {
        //创建连接
        try {
            //使用读取本地文件的方式添加参数
            connection = ConnectionFactory.createConnection();

        } catch (IOException e) {
            e.printStackTrace();
        }

//        //创建异步连接
//        CompletableFuture<AsyncConnection> asyncConnection = ConnectionFactory.createAsyncConnection();

    }

    public static Connection getConnection(){
        return connection;
    }


    public static void closeConnection() {
        if (connection!=null){
            try {
                connection.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    
}

 

posted @ 2022-09-22 15:24  软工小蜗牛  阅读(100)  评论(0编辑  收藏  举报