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(); } } } }
标签:创建,连接,connection,static,hbase,多线程,public From: https://www.cnblogs.com/-0112/p/16719466.html