Skip to content

Commit 93fd2c9

Browse files
hpoettkerfmbenhassine
authored andcommitted
Keep heap lean during remote partition polling
Resolves #4598
1 parent b94f7cf commit 93fd2c9

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

spring-batch-integration/src/main/java/org/springframework/batch/integration/partition/MessageChannelPartitionHandler.java

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2023 the original author or authors.
2+
* Copyright 2009-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -251,24 +251,22 @@ protected Set<StepExecution> doHandle(StepExecution managerStepExecution,
251251

252252
private Set<StepExecution> pollReplies(final StepExecution managerStepExecution, final Set<StepExecution> split)
253253
throws Exception {
254-
final Set<StepExecution> result = new HashSet<>(split.size());
254+
Set<Long> partitionStepExecutionIds = split.stream().map(StepExecution::getId).collect(Collectors.toSet());
255255

256256
Callable<Set<StepExecution>> callback = () -> {
257-
Set<Long> currentStepExecutionIds = split.stream().map(StepExecution::getId).collect(Collectors.toSet());
258257
JobExecution jobExecution = jobExplorer.getJobExecution(managerStepExecution.getJobExecutionId());
259-
jobExecution.getStepExecutions()
258+
Set<StepExecution> finishedStepExecutions = jobExecution.getStepExecutions()
260259
.stream()
261-
.filter(stepExecution -> currentStepExecutionIds.contains(stepExecution.getId()))
262-
.filter(stepExecution -> !result.contains(stepExecution))
260+
.filter(stepExecution -> partitionStepExecutionIds.contains(stepExecution.getId()))
263261
.filter(stepExecution -> !stepExecution.getStatus().isRunning())
264-
.forEach(result::add);
262+
.collect(Collectors.toSet());
265263

266264
if (logger.isDebugEnabled()) {
267265
logger.debug(String.format("Currently waiting on %s partitions to finish", split.size()));
268266
}
269267

270-
if (result.size() == split.size()) {
271-
return result;
268+
if (finishedStepExecutions.size() == split.size()) {
269+
return finishedStepExecutions;
272270
}
273271
else {
274272
return null;

0 commit comments

Comments
 (0)