Phoenix批量提交优化,官网的demo

Posted questionszhang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的在循环外围最后提交,所以保证了,所有数据最终都是会被提交.

以上是关于Phoenix批量提交优化,官网的demo的主要内容,如果未能解决你的问题,请参考以下文章