help wanted
Repository metrics
- Stars
- (33,728 stars)
- PR merge metrics
- (30d に merged PR はありません)
説明
问题描述,使用Web导出文件是,大对象无法被回收,导致OOM
异常代码
public void downloadDebugInfo(
HttpServletResponse response,
@RequestParam(name = "taskId") String taskId,
@RequestParam(name = "versionId") String versionId) throws IOException {
long startTime = System.currentTimeMillis();
ExportResult exportResult = diffService.getDebugResult(Long.valueOf(taskId), Long.valueOf(versionId));
long endTime = System.currentTimeMillis();
long elapsedTime = endTime - startTime;
log.info("导出计算运行时间:" + elapsedTime + "ms");
// 接口测试 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postman
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
// 这里URLEncoder.encode可以防止中文乱码
String fileName = URLEncoder.encode(exportResult.getFileName(), "UTF-8").replaceAll("\\+", "%20");
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
try (ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).build()) {
if (!CollectionUtils.isEmpty(exportResult.getNoteDebugInfoList())) {
List<NoteSearchDataExpExcel> noteDebugInfoList = exportResult.getNoteDebugInfoList();
WriteSheet gsbWriteSheet = EasyExcel.writerSheet(0, "Diff结果").head(NoteSearchDataExpExcel.class).build();
excelWriter.write(noteDebugInfoList, gsbWriteSheet);
} else {
List<NoteFeedDataExpExcel> noteDebugInfoList = exportResult.getNoteFeedDataExpExcelList();
WriteSheet gsbWriteSheet = EasyExcel.writerSheet(0, "Diff结果").head(NoteFeedDataExpExcel.class).build();
excelWriter.write(noteDebugInfoList, gsbWriteSheet);
}
} catch (Exception e) {
log.error("scoring export error. ", e);
throw new DroomException("导出Diff异常");
} finally {
exportResult.clear();
exportResult = null;
System.gc();
}
}
问题描述
使用Web导出文件是,大对象无法被回收,导致OOM, 通过分析代码里面的 List noteDebugInfoList 无法被回收