Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Hbase连接池_Java_Hbase - Fatal编程技术网

Java Hbase连接池

Java Hbase连接池,java,hbase,Java,Hbase,我正在尝试创建hbase连接池。我试过下面的东西。但我不知道后果如何。这会影响我的表现吗?有人能帮忙吗?主机可以是远程的,甚至是本地的 HashMap cons = new HashMap(); public void getDataFromHbase(String host, String tableid){ conf.set("hbase.zookeeper.quorum", host); ThreadPoolExecutor executor= (T

我正在尝试创建hbase连接池。我试过下面的东西。但我不知道后果如何。这会影响我的表现吗?有人能帮忙吗?主机可以是远程的,甚至是本地的

HashMap cons = new HashMap();
    public void getDataFromHbase(String host, String tableid){
        conf.set("hbase.zookeeper.quorum", host);
        ThreadPoolExecutor executor= (ThreadPoolExecutor) Executors.newCachedThreadPool();
        executor.setMaximumPoolSize(50);
        if(cons.get(host+"tableA_"+tableid) != null){
            table1 = cons.get(host+"tableA_"+tableid);
            table2 = cons.get(host+"tableB_"+tableid);
        }
        else{
            table1 = new HTable(conf,Bytes.toBytes("tableA_"+tableid),executor);
            table2 = new HTable(conf,Bytes.toBytes("tableB_"+tableid),executor);
            cons.put(host+"tableA_"+tableid,table1);
            cons.put(host+"tableB_"+tableid,table2);
        }
        Scan scan = new Scan();
        scan.addFamily(Bytes.toBytes("n"));
        scan.setCaching(1000);
        ResultScanner resultScanner = table1.getScanner(scan);
        ResultScanner resultScannerB = table2.getScanner(scan);
    }
我建议。。而是自己的连接管理,它更容易出错,也更难调试

类HTablePool

java.lang.Object org.apache.hadoop.hbase.client.HTablePool

所有实现的接口:

可关闭的,可自动关闭的

不赞成。改用HConnection.getTable(字符串)

公共类HTablePool扩展对象实现可关闭

一个简单的HTable实例池。每个HTablePool充当的池 所有的桌子。要使用,请实例化一个HTablePool并使用getTable(String) 从池中获取HTable。这种方法不再需要了, 客户端应该调用HTableInterface.close(),而不是返回 将表添加到池中完成后,请关闭的实例 通过调用HTableInterface.close()而不是 将表返回到池中(已弃用) putTable(HTableInterface)。可以使用maxSize创建池,该 定义将为每个项目保留的最可更新的引用 桌子否则,默认值为Integer.MAX_值

池将管理自己与群集的连接。请参见 HConnectionManager


我的回答有用吗。如果有问题,你可以问。