Spring batch item reader to handle the chunk processing for rest api calls

I need some advice on how chunks based approach can be used on my ITEM READER.

i have 200k and above records which i consume from an api.

in this code if i put page size as 100 and chunk size as 100, suppose think i have only 233 records not 200k. then my reader first its returning 100, 100, 33 first all reader is done , then its going to processor now processor is run thrice for 100, 100, 33.

so i want to know is there a way if i say chunk size 100 i dont want to wait until all that 200k in reader is done then going to processor can i send 100 to processor and writer then comeback to reader again process 100 records pass them to processor, writer.

so if there are million of records of rest api, which approach is best for reader.

@RequiredArgsConstructor
public class AssignTermsToEntityItemReader implements ItemReader<AssignTermEntityRequest> {
    private final NativeApiService nativeApiService;
    @Value("${hmdmg.default.page-size}")
    private Integer pageSize;
    @Value("${batch.entity-terms-assign-job.batchSize}")
    private Integer chunkSize;
    private int currentOffset = 0;
    private List<NativeEntity> accumulatedBatch = new ArrayList<>();

    @Override
    public AssignTermEntityRequest read() {
        while (accumulatedBatch.size() < chunkSize) {
            List<NativeEntity> currentBatch = fetchNextBatch();
            if (currentBatch.isEmpty()) {
                break;
            }
            accumulatedBatch.addAll(currentBatch);
        }

        if (accumulatedBatch.isEmpty()) {
            return null;
        }

        List<NativeEntity> itemsToProcess = new ArrayList<>(accumulatedBatch.subList(0, Math.min(chunkSize, accumulatedBatch.size())));
        accumulatedBatch.subList(0, itemsToProcess.size()).clear();

        return AssignTermEntityRequest.builder().nativeEntities(itemsToProcess).build();
    }

    private List<NativeEntity> fetchNextBatch() {
        NativeSearchResult nativeSearchResult = searchHiveColumns(currentOffset);
        currentOffset += pageSize;
        return nativeSearchResult.getEntities();
    }


    private NativeSearchResult searchHiveColumns(int offset) {
        NativeSearchRequest searchRequestToRetrieveHiveColumns = createSearchRequestToRetrieveHiveColumns(offset);
        ResponseEntity<NativeSearchResult> nativeSearchResultResponseEntity = nativeApiService.searchHiveColumns(searchRequestToRetrieveHiveColumns);
        return Optional.ofNullable(nativeSearchResultResponseEntity)
                .map(ResponseEntity::getBody)
                .orElse(new NativeSearchResult());
    }

    private NativeSearchRequest createSearchRequestToRetrieveHiveColumns(int offset) {
        return NativeSearchRequest.builder()
                .typeName(TYPE_NAME)
                .excludeDeletedEntities(true)
                .sortOrder("ASCENDING")
                .sortBy("name")
                .entityFilters(NativeEntityFilter.builder()
                        .condition(NativeSearchCondition.AND)
                        .criterion(Arrays.asList(
                                NativeSearchCriteria.builder()
                                        .attributeName("name")
                                        .operator("eq")
                                        .attributeValue("account_number")
                                        .build())).build())
                .offset(String.valueOf(offset))
                .limit(String.valueOf(pageSize))
                .build();
    }
}

i tried the 3 things of chunk tests

one pagesize less than chunk size, pagesize greater than chunk size, page size equal to chunk size.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật