一、應(yīng)用線程導(dǎo)入
青云譜網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián),青云譜網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為青云譜上千多家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站制作要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的青云譜做網(wǎng)站的公司定做!
1、創(chuàng)建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、創(chuàng)建線程
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(); //這里創(chuàng)建兩個(gè)線程,需要可以繼續(xù)創(chuàng)建~ } } 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>
數(shù)據(jù)導(dǎo)入速度慢。之前put方法每執(zhí)行一次就要new一個(gè)新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進(jìn)行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<Put> 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(); } } } }
然后在主函數(shù)中:
List<Put> puts=new ArrayList<Put>(); 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("源網(wǎng)"+i)); puts.add(put); } System.out.println("寫入List完成"); mmm.moreput("yuan", puts);
當(dāng)前題目:HBaseFilter使用方法(三)------批量put導(dǎo)入
分享網(wǎng)址:http://muchs.cn/article36/pipesg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈、外貿(mào)建站、網(wǎng)站排名、網(wǎng)站導(dǎo)航、動(dòng)態(tài)網(wǎng)站、品牌網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)