Код: Выделить всё
try (PreparedStatement ps = conn.prepareStatement(MY_SQL)) {
ps.setFetchSize(100);
ResultSet rs = ps.executeQuery();
do {
List chunk = new ArrayList();
while (rs.next() && (rowsReadInThisBatch < myBatchSize)) {
MyEntity entity = new MyEntity();
myEntity.setSomeCol(rs.getLong("some_col");
myEntity.setSomeCol2(rs.getLong("some_col2");
chunk.add(entity)
rowsReadInThisBatch++;
}
// lost more code.
proccess(chunk);
writeBackToDB(cunk);
// lots more code
}while (rowsReadInThisBatch == myBatchSize);
Код: Выделить всё
try(Stream myStream = postRepository.streamByCreatedOnSince(yesterday)) {
myStream.forEach(
....
);
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... of-records