Это мой код:
Код: Выделить всё
public String extractInformationAndGenerateExcel(String username, List comuniList, String uniqueFileName) throws IOException {
Path tempFilePath = Files.createTempFile("temp_", ".txt");
try (Stream contrattiEAttrezzatureStream = contrattiAttrezzatureRepository.getReportContrattiAttrezzature(username, comuniList);
ByteArrayOutputStream out = new ByteArrayOutputStream();
BufferedWriter writer = Files.newBufferedWriter(tempFilePath, StandardOpenOption.WRITE)
)
{
logger.info("Start to write file??????");
contrattiEAttrezzatureStream.forEach(contratto -> {
try {
writer.write(contratto.toString());
writer.newLine();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
logger.info("Finish");
return "Finish?";
}catch (Exception e) {
throw new RuntimeException(e);
}finally {
if (tempFilePath != null && Files.exists(tempFilePath)) {
try {
Files.delete(tempFilePath);
} catch (IOException e) {
logger.error("Error", e);
}
}
}
}
Моя ситуация с использованием VisualVM такова

Вот изображение профиля потока моего Java-приложения, показывающее время выполнения и состояние различных потоков:

Вопросы:
- Правильно ли использование Stream?
- Правильно ли есть что-то, что я не рассматриваю?
Подробнее здесь: https://stackoverflow.com/questions/790 ... ta-streams