大家好,请教个问题,我的hbase多线程并发查询数据出现问题,有的线程查询成功,有的失败
我的hbase使用的版本是1.2.1,使用的hbase工具类为
package com.jinhetech.xman.utils.hbase; import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.ConnectionFactory; import org.apache.hadoop.hbase.client.Table; import com.jinhetech.xman.utils.log.ErrInLog; import com.jinhetech.xman.utils.log.Logger; /** * hbase客户端 * @author xxmeng * */ public class HbaseClient { private static final Logger LOGGER = Logger.getLogger(HbaseClient.class); private Configuration conf = null; private Connection conn = null; private static HbaseClient instance = null; private HbaseClient(){ init(); } public void init(){ try{ /*conf.set("hbase.zookeeper.quorum", "127.0.0.1"); conf.set("zookeeper.znode.parent", "/hbase"); conf.set("hbase.zookeeper.property.clientPort", "2181"); conf.set("hbase.client.pause", "50"); conf.set("hbase.client.retries.number", "3"); conf.set("hbase.rpc.timeout", "2000"); conf.set("hbase.client.operation.timeout", "3000"); conf.set("hbase.client.scanner.timeout.period", "10000"); */ conf = HBaseConfiguration.create(); conf.addResource("config/hbase-site.xml"); conn = ConnectionFactory.createConnection(conf); }catch(Exception e){ LOGGER.info("初始化hbase连接失败:"+ErrInLog.errInfo(e)); } } public static HbaseClient getInstance(){ if(instance == null){ synchronized (HbaseClient.class) { if(instance == null){ instance = new HbaseClient(); } } } return instance; } /** * 获取htable操作类 * @param tableName * @return * @throws IOException */ public Table getHtable(String tableName) throws IOException{ return conn.getTable(TableName.valueOf(tableName)); } /** * * @param hTableInterface */ public void relaseHtable(Table table){ if(table == null){ return; } try { table.close(); } catch (IOException e) { LOGGER.info("hbase中表关闭失败:"+ErrInLog.errInfo(e)); } } /** * 关闭hbase连接 */ public void destory(){ try { conn.close(); instance = null; } catch (IOException e) { LOGGER.info("hbase中连接关闭失败:"+ErrInLog.errInfo(e)); } } }
HbaseClient client = HbaseClient.getInstance();
Table table = null;
rs = table.getScanner(sc);
// try {
if (rs != null) {
for (Result r : rs) {//这句开始报错
Map<String, Object> map = new HashMap<String, Object>();
for (KeyValue keyValue : r.raw()) {
map.put(new String(keyValue.getQualifier()),
new String(keyValue.getValue()));
}
protoList.add(map);
}
}
} catch (Exception e) {
logger.info("稻瘟病积分计算查询hbase异常");
logger.info("异常:" + ErrInLog.errInfo(e));
} finally {
client.relaseHtable(table);
}
这是怎么回事呢
你只关了table, ResultScanner并没有关闭恩,我先关闭下试试回复<aclass="referer"target="_blank">@梦幻女侠:不用,整个项目开启一个hbase连接就可以了,它是线程安全的重量级连接rs关闭就可以了么?hbase连接不用关闭吧
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。