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的在循环外围最后提交,所以保证了,所有数据最终都是会被提交.

posted @ 2019-07-27 12:15  Questions张  阅读(1345)  评论(0编辑  收藏  举报