배치 프로세싱 최적화 필요
@Service
@Transactional
public class MemberBatchService {
private final EntityManager entityManager;
private final MemberRepository memberRepository;
@Autowired
public MemberBatchService(EntityManager entityManager, MemberRepository memberRepository) {
this.entityManager = entityManager;
this.memberRepository = memberRepository;
}
public void processMembersInBatches(int batchSize) {
int pageNumber = 0;
Page<Member> page;
do {
page = memberRepository.findAll(PageRequest.of(pageNumber, batchSize));
for (Member member : page.getContent()) {
// 처리 로직
member.setProcessed(true);
memberRepository.save(member);
}
entityManager.flush();
entityManager.clear();
pageNumber++;
} while (page.hasNext());
}
}