hbase1.2.1多线程并发查询问题
大家好,请教个问题,我的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);
}
这是怎么回事呢
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
rs关闭就可以了么?hbase连接不用关闭吧
回复
@梦幻女侠 : 不用,整个项目开启一个hbase连接就可以了, 它是线程安全的重量级连接
恩,我先关闭下试试
你只关了table, ResultScanner并没有关闭