Skip to content

Commit 0056722

Browse files
committed
Refine contribution #4715
- Deprecate stop method - Fix imports - Update Javadocs
1 parent bdb2bfc commit 0056722

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobOperator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,9 @@ public boolean stop(JobExecution jobExecution) throws JobExecutionNotRunningExce
367367
}
368368
}
369369
catch (NoSuchJobException e) {
370-
logger.warn("Cannot find Job object in the job registry. StoppableTasklet#stop(StepExecution stepExecution) will not be called", e);
370+
logger.warn(
371+
"Cannot find Job object in the job registry. StoppableTasklet#stop(StepExecution stepExecution) will not be called",
372+
e);
371373
}
372374

373375
return true;

spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/StoppableTasklet.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013 the original author or authors.
2+
* Copyright 2013-present 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.
@@ -15,7 +15,7 @@
1515
*/
1616
package org.springframework.batch.core.step.tasklet;
1717

18-
import org.springframework.batch.core.StepExecution;
18+
import org.springframework.batch.core.step.StepExecution;
1919
import org.springframework.batch.core.launch.JobOperator;
2020
import org.springframework.batch.core.step.StepContribution;
2121

@@ -38,17 +38,20 @@ public interface StoppableTasklet extends Tasklet {
3838
/**
3939
* Used to signal that the job this {@link Tasklet} is executing within has been
4040
* requested to stop.
41+
* @deprecated Since 6.0, use {@link #stop(StepExecution)} instead.
4142
*/
43+
@Deprecated(since = "6.0", forRemoval = true)
4244
void stop();
4345

4446
/**
4547
* Used to signal that the job should stop, providing access to the current
4648
* {@link StepExecution} context.
47-
*
48-
* @param stepExecution the current {@link StepExecution} context in which the job
49-
* is being executed
49+
* @param stepExecution the current {@link StepExecution} context in which the job is
50+
* being executed
51+
* @since 6.0
5052
*/
5153
default void stop(StepExecution stepExecution) {
5254
stop();
5355
}
56+
5457
}

spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SystemCommandTasklet.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,17 +279,21 @@ public void stop() {
279279
/**
280280
* Interrupts the execution of the system command if the given {@link StepExecution}
281281
* matches the current execution context. This method allows for granular control over
282-
* stopping specific step executions, ensuring that only the intended command is halted.
283-
*
282+
* stopping specific step executions, ensuring that only the intended command is
283+
* halted.
284+
* <p>
285+
* This method will interrupt the thread executing the system command only if
286+
* {@link #setInterruptOnCancel(boolean)} has been set to true. Otherwise, the
287+
* underlying command will be allowed to finish before the tasklet ends.
284288
* @param stepExecution the current {@link StepExecution} context; the execution is
285289
* interrupted if it matches the ongoing one.
286290
* @since 6.0
287291
* @see StoppableTasklet#stop(StepExecution)
288292
*/
289293
@Override
290294
public void stop(StepExecution stepExecution) {
291-
if (stepExecution.equals(execution)) {
292-
stopped = true;
295+
if (stepExecution.equals(this.execution)) {
296+
this.stopped = true;
293297
}
294298
}
295299

0 commit comments

Comments
 (0)