POI is used in the Java project to export millions of pieces of data to Excel, but a memory overflow exception occurs.
there are the following problems to consider
- the number of POI exports is limited to 6w +
- A large amount of data will lead to memory overflow
the current practice is to split every 6w pieces of data to create a new sheet, but this is very slow
List<List<Object>> result = new ArrayList<List<Object>>();
List<Object> dataList = new ArrayList<Object>();
if (resultList != null) {
for (int i = 0; i < resultList.size(); iPP) {
Map<String, Object> map = getDataByClass(resultList.get(i));
dataList.add(map);
if (dataList.size() % 60000 == 0 && dataList.size() != 0) {
result.add(dataList);
dataList = new ArrayList<Object>();
}
}
if(dataList.size()!=0){
result.add(dataList);
}
}
I hope you can give some suggestions and think of a better solution to this problem ~