I'm trying to read an Excel with over 500.000 lines in my Spring Boot Application. The problem is that I get a java.net.SocketTimeoutException: Read timed out
AFTER already having read all lines in. The problem occurs in the following method (without showing any Error or Exception in the console):
private List<XYZEntry> importFile(XYZ file) throws ServiceException {
var xyzToImport = new HashSet<XYZ>();
List<XYZEntry> invalidXYZ = new ArrayList<>();
try(var wb = WorkbookFactory.create(new ByteArrayInputStream(file.getContent()))) {
for(var row: wb.getSheetAt(0)) {
if(row.getRowNum() == 0) {
// Skip header
continue;
}
DataFormatter formatter = new DataFormatter();
var potentialXYZ = formatter.formatCellValue( row.getCell( 0 ) ).trim();
if(isXYZValidToImport(potentialXYZ)) {
xyzsToImport.add(new XYZ(potentialXYZ));
} else {
invalidXYZ.add(new XYZEntry(potentialXYZ, row.getRowNum() + 1));
}
}
if(CollectionUtils.isNotEmpty(invalidXYZ)) {
file.setInvalidEntries(invalidXYZ.size());
log.info(
"While importing the file {} | {} invalid XYZs was skipped: {}",
file.getFilename(),
invalidXYZ.size(),
String.join(",", invalidXYZ.toString())
);
}
if(CollectionUtils.isEmpty(xyzToImport)) {
log.warn(
"No valid XYZwas found in File {}, nothing imported.",
file.getFilename()
);
file.setStatus( XYZStateEnum.NO_IMPORTS );
} else {
transactionHelper.executeInNewTransaction(() -> {
xyzsRepository.deleteAll();
xyzsRepository.saveAll(xyzsToImport);
// this return ist not reached anymore
return null;
});
file.setValidEntries(xyzsToImport.size());
file.setStatus(XYZStateEnum.IMPORTED);
}
} catch(IOException e) {
file.setStatus(XYZStateEnum.ERROR);
filesRepository.save(file);
throw new ServiceException("XYZ Import failed.", e);
}
filesRepository.save(file);
return invalidXYZ;
}
I found out that the code is running until the saveAll()
method stops there.