Categories
Mastering Development

Write an executor service to process in a batch of 100 records

private void startProcess() throws Exception { ListObjectsV2Request listObjectsV2Request = new ListObjectsV2Request(); listObjectsV2Request.setBucketName(bucket); listObjectsV2Request.setPrefix(prefix); ListObjectsV2Result listObjectsV2Result; do { listObjectsV2Result = s3Client.listObjectsV2(listObjectsV2Request); execute(listObjectsV2Result.getObjectSummaries()); listObjectsV2Request.setContinuationToken(listObjectsV2Result.getNextContinuationToken()); } while(listObjectsV2Result.isTruncated()); } public void execute(List<S3ObjectSummary> s3ObjectSummaries) throws Exception{ List<List<S3ObjectSummary>> results = partition(s3ObjectSummaries, 100); List<Future<?>> futureResults = new ArrayList<>(); for (List<S3ObjectSummary> summaries : results) { futureResults.add(executor.submit(() -> { process(summaries); return true; })); } […]