lastBatch= fileTotal;
arrayCount=1;
List<Map<String, String>>[] list = new List[arrayCount];
for (int i = 0; i < arrayCount; i++) {
list[i] = new ArrayList<>();
}
in = new LineNumberReader(new InputStreamReader(new FileInputStream(file), "GBK"));
String line = null;
int lineNumber = 0;
int batchInsert = 0;
for (int m = 0; m < arrayCount; m++){
List<Map<String, String>> singlelist = list[m];
int countMax
int countMin = (singleBatch * m);
if (m == (arrayCount - 1)){
countMax = countMin + lastBatch
}
while (((line = in.readLine()) != null) && ((lineNumber = in.getLineNumber()) > count
//line转换为map
Map<String, String> singleMap = switch2Map(line, type);
singleList.add(singleMap)
long insertStart = System.currentTimeMillis();
String sgl = String.format("insert into t_xxx%02d values (?,?,?,
?,?,?,?,?...
if (type.equals(LnnrConstant.AAA)){
sql = String.format("insert into t_xxx%02d values (?,?,?,?,???,?,????...
}
...
}
List<Map<String, String>> singlelist = list[m];
在这一行,创建了一个过百的数组,每个数组放1000的元素,但是使用后没有清空,也就一直没有被释放,导致一直占用内存。clear()后代码如下:
...
batchInsert += ints.length;
long insertEnd = System.currentTimeillis();
long singleTime = insertEnd - insertstart;
singleList.clear;
listi[m] = null;
}
if(fileTotal= batchInsert){
logger.error(String.format("文件批量插队结束,入库总数[%s]与文件总数[s]不一致!",batchInsert, file);
else {
logger,info(String,format("文件"+ sym + "批量插入成功,入库总数[%s],文件总数[%s]", batchInsert, fileTotal);
Latch.countDown();
logger.info("latchCount>>>" + latch. getCount())
tempReader.close()
in.ctose();
/*} catch (Exception e){
/*logger,info("文件" + sym + "批量插入结束,耗时: " + timeTotal + "毫秒");*/
loggererror(e.getMessage());
throw new BatchRuntimeException(e);}*/
...