0

我正在为我的 sql insert stmt 使用 ibatis。在我的代码中,我从文件夹中逐行解析文件。符合条件的每一行都需要插入数据库。单次运行程序中的插入总数可以是 200k 左右的任何位置。

    SqlSession sess = null;    
    this.sess = sf.openSession(ExecutorType.BATCH, false);
    for (each file) {
     for( each line matching criteria ){
         this.sess.insert("com.logs.util.insertFileInfo", fileData);
         insertcount++;
         if(insert count == 10)
              this.sess.commit();
         }    
      }
      if(insert count > 0){
           this.sess.commit();
      }   
    }

这种风格会慢慢占用大量内存,并在一段时间后抛出 OutOfMemory 异常。我怎样才能在这里提高性能?

4

1 回答 1

0

Is it your intention to commit after every 10 inserts? It looks like you only do so after the first 10 inserts. I guess that you would need something like

if ((insertCount % 10) == 0) {
   this.sess.commit();
}

Those uncommitted changes have to be stored somewhere. I'm not familiar with Ibatis but if the uncommitted changes are being stored in a buffer allocated by Ibatis then you will eventually run out of memory if you don't commit the changes.

于 2010-10-19T16:21:18.177 回答