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的在循環外圍最后提交,所以保證了,所有數據最終都是會被提交.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM