HBase Filter使用方法(三)------批量put导入
发表于:2025-11-20 作者:千家信息网编辑
千家信息网最后更新 2025年11月20日,一、应用线程导入1、创建put方法public class mmm{ public static Configuration config=new Configuration();;
千家信息网最后更新 2025年11月20日HBase Filter使用方法(三)------批量put导入
一、应用线程导入
1、创建put方法
public class mmm{ public static Configuration config=new Configuration();; static{ config.set("hbase.zookeeper.property.clientPoint","2181"); config.set("hbase.zookeeper.quorum","hbase"); config.set("dfs.socket.timeout", "180000"); } public static void put(String tablename,String RowKey,String Family,String Qualifier,String Value){ HTable h=null; try{ h=new HTable(config,tablename); Put put=new Put(Bytes.toBytes(RowKey)); put.add(Bytes.toBytes(Family), Bytes.toBytes(Qualifier), Bytes.toBytes(Value)); h.put(put); }catch(Exception e){e.printStackTrace();}finally{ try { h.close(); } catch (IOException e) { e.printStackTrace(); } } }}2、创建线程
public class PutXX { public static void main(String[] args) { run1 r1=new run1(); Thread rr1=new Thread(r1); rr1.start(); run2 r2=new run2(); Thread rr2=new Thread(r2); rr2.start(); //这里创建两个线程,需要可以继续创建~}}class run1 implements Runnable{public void run() {for(int i=0;i<=10000000;i++){ mmm.put("yuan", ""+i+"", "property", "yuan_name", "xx"+i); System.out.println(i); }}}class run2 implements Runnable{public void run() {for(int i=10000001;i<=20000000;i++){ mmm.put("yuan", ""+i+"", "property", "yuan_name", "xx"+i); System.out.println(i); }}}<2015.2.2>
数据导入速度慢。之前put方法每执行一次就要new一个新HTable然后释放资源。。太墨迹了
新put
public static void NBput(String tablename,int RowKey,String Family,String Qualifier,String Value){ HTable h=null; try { h=new HTable(config,tablename); for(int i=RowKey;i<=(RowKey+10000000);i++){ String row=""+i+""; Put put=new Put(Bytes.toBytes(row)); put.add(Bytes.toBytes(Family), Bytes.toBytes(Qualifier), Bytes.toBytes(Value)); h.put(put); System.out.println(i); } } catch (IOException e) { e.printStackTrace(); }finally{ try { h.close(); } catch (IOException e) { e.printStackTrace(); } } }修改以后速度明显提升啊我去!之前那方法太傻缺了。。。。
二、使用List进行put
public class mmm{ public static Configuration config=new Configuration();; static{ config.set("hbase.zookeeper.property.clientPoint","2181"); config.set("hbase.zookeeper.quorum","hbase"); config.set("dfs.socket.timeout", "180000"); } /* * 批量put * */ public static void moreput(String tablename, List puts){ HTable h=null; try{ h=new HTable(config,tablename); Put put=new Put(Bytes.toBytes("")); puts.add(put); h.put(puts); }catch(Exception e){ e.printStackTrace(); }finally{ try { puts.clear(); h.close(); } catch (IOException e) { e.printStackTrace(); } } }} 然后在主函数中:
Listputs=new ArrayList (); for(int i=100000;i<=5000000;i++){ System.out.println(i); Put put=new Put(Bytes.toBytes(""+i+"")); put.add(Bytes.toBytes("property"), Bytes.toBytes("yuan_name"), Bytes.toBytes("源网"+i)); puts.add(put);} System.out.println("写入List完成"); mmm.moreput("yuan", puts);
方法
线程
速度
明显
两个
函数
墨迹
数据
资源
源网
应用
使用方法
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
计算机网络安全探讨
株洲软件开发大学
diy 服务器
行政单位网络安全汇报
kmeans网络安全
加强网络安全信息收集分析
腾讯服务器同步时间
web软件开发原型工具有哪些
服务器硬盘分区
电脑服务器一直没响应怎么办
全国网络安全专业就业方向
服务器空间被占用太多
网络安全交易主题手抄报
福建师范大学协和学院数据库
在服务器上使用校园账号登录
无法进入的app是服务器的问题
dota2 几个服务器
租用服务器做节点安全吗
全国计算机四级网络技术报考
腾讯投资网络安全
安徽新一代软件开发服务推广
精英网络技术开发优化价格
数据库最新密钥
下载自动连接免费网络安全吗
网页设计需要学习数据库吗
服务器vt是什么
网络安全保密协定
电信云桌面服务器版本
大象数据库拷贝某一天的数据
我国近段时间网络安全事件