Skip to content

Commit

Permalink
Fix the random test failure of purgeInMemoryRepository #387
Browse files Browse the repository at this point in the history
  • Loading branch information
liweinan committed Oct 12, 2023
1 parent a9cf188 commit 9de8fea
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import java.util.Locale;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

import jakarta.batch.operations.NoSuchJobExecutionException;
import jakarta.batch.runtime.JobExecution;
import jakarta.batch.runtime.JobInstance;
Expand Down Expand Up @@ -97,13 +99,21 @@ protected void startJob(final Job job) {
jobExecution = (JobExecutionImpl) jobOperator.getJobExecution(jobExecutionId);
}

private ReentrantLock termLock = new ReentrantLock();

protected void awaitTermination(final JobExecutionImpl... exes) throws InterruptedException {
final JobExecutionImpl exe = exes.length == 0 ? jobExecution : exes[0];
exe.awaitTermination(getJobTimeoutSeconds(), TimeUnit.SECONDS);
stepExecutions = jobOperator.getStepExecutions(exe.getExecutionId());
if (!stepExecutions.isEmpty()) {
stepExecution0 = (StepExecutionImpl) stepExecutions.get(0);
try {
termLock.lock();
final JobExecutionImpl exe = exes.length == 0 ? jobExecution : exes[0];
exe.awaitTermination(getJobTimeoutSeconds(), TimeUnit.SECONDS);
stepExecutions = jobOperator.getStepExecutions(exe.getExecutionId());
if (!stepExecutions.isEmpty()) {
stepExecution0 = (StepExecutionImpl) stepExecutions.get(0);
}
} finally {
termLock.unlock();
}

}

protected void startJobAndWait(final String jobXml) throws Exception {
Expand Down

0 comments on commit 9de8fea

Please sign in to comment.