File tree Expand file tree Collapse file tree 3 files changed +33
-2
lines changed
spring-batch-core/src/main/java/org/springframework/batch/core Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change 8282 * @author Mahmoud Ben Hassine
8383 * @author Andrey Litvitski
8484 * @author Yejeong Ham
85+ * @author Hyunsang Han
8586 * @since 2.0
8687 * @deprecated since 6.0 in favor of {@link TaskExecutorJobOperator}. Scheduled for
8788 * removal in 6.2 or later.
@@ -348,7 +349,7 @@ public boolean stop(JobExecution jobExecution) throws JobExecutionNotRunningExce
348349 Tasklet tasklet = taskletStep .getTasklet ();
349350 if (tasklet instanceof StoppableTasklet stoppableTasklet ) {
350351 StepSynchronizationManager .register (stepExecution );
351- stoppableTasklet .stop ();
352+ stoppableTasklet .stop (stepExecution );
352353 StepSynchronizationManager .release ();
353354 }
354355 }
@@ -366,7 +367,7 @@ public boolean stop(JobExecution jobExecution) throws JobExecutionNotRunningExce
366367 }
367368 }
368369 catch (NoSuchJobException e ) {
369- logger .warn ("Cannot find Job object in the job registry. StoppableTasklet#stop() will not be called" , e );
370+ logger .warn ("Cannot find Job object in the job registry. StoppableTasklet#stop(StepExecution stepExecution ) will not be called" , e );
370371 }
371372
372373 return true ;
Original file line number Diff line number Diff line change 1515 */
1616package org .springframework .batch .core .step .tasklet ;
1717
18+ import org .springframework .batch .core .StepExecution ;
1819import org .springframework .batch .core .launch .JobOperator ;
1920import org .springframework .batch .core .step .StepContribution ;
2021
2930 * so the appropriate thread safety and visibility controls should be put in place.
3031 *
3132 * @author Will Schipp
33+ * @author Hyunsang Han
3234 * @since 3.0
3335 */
3436public interface StoppableTasklet extends Tasklet {
@@ -39,4 +41,14 @@ public interface StoppableTasklet extends Tasklet {
3941 */
4042 void stop ();
4143
44+ /**
45+ * Used to signal that the job should stop, providing access to the current
46+ * {@link StepExecution} context.
47+ *
48+ * @param stepExecution the current {@link StepExecution} context in which the job
49+ * is being executed
50+ */
51+ default void stop (StepExecution stepExecution ) {
52+ stop ();
53+ }
4254}
Original file line number Diff line number Diff line change 6161 * @author Will Schipp
6262 * @author Mahmoud Ben Hassine
6363 * @author Injae Kim
64+ * @author Hyunsang Han
6465 */
6566public class SystemCommandTasklet implements StepExecutionListener , StoppableTasklet , InitializingBean {
6667
@@ -275,4 +276,21 @@ public void stop() {
275276 stopped = true ;
276277 }
277278
279+ /**
280+ * Interrupts the execution of the system command if the given {@link StepExecution}
281+ * 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+ *
284+ * @param stepExecution the current {@link StepExecution} context; the execution is
285+ * interrupted if it matches the ongoing one.
286+ * @since 6.0
287+ * @see StoppableTasklet#stop(StepExecution)
288+ */
289+ @ Override
290+ public void stop (StepExecution stepExecution ) {
291+ if (stepExecution .equals (execution )) {
292+ stopped = true ;
293+ }
294+ }
295+
278296}
You can’t perform that action at this time.
0 commit comments