我正在为我的 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 异常。我怎样才能在这里提高性能?