zoukankan      html  css  js  c++  java
  • Phoenix批量提交优化,官网的demo

    1 Phoenix的批量insert官网代码,最佳实践

    try (Connection conn = DriverManager.getConnection(url)) {
      conn.setAutoCommit(false);
      int batchSize = 0;
      int commitSize = 1000; // number of rows you want to commit per batch.  
      try (Statement stmt = conn.prepareStatement(upsert)) {
        stmt.set ... while (there are records to upsert) {
          stmt.executeUpdate(); 
          batchSize++; 
          if (batchSize % commitSize == 0) { 
            conn.commit(); 
          } 
       } 
     conn.commit(); // commit the last batch of records 
     }
    

      

    2 解读代码

      循环的过程中,每1000条数据批量提交一次,不足1000的在循环外围最后提交,所以保证了,所有数据最终都是会被提交.

  • 相关阅读:
    Apollo与ROS
    QT windeployqt
    自定义QGraphicsItem
    ROS与C++
    aptitude与apt-get
    解决tcp粘包问题
    网络中两台主机通信
    I/O多路复用之select、poll、epoll
    Nginx命令行控制
    C++11
  • 原文地址:https://www.cnblogs.com/QuestionsZhang/p/11254552.html
Copyright © 2011-2022 走看看