From 30ba4e39c58b5b32d41f38726e29b4bd60e40286 Mon Sep 17 00:00:00 2001 From: HyunSangHan Date: Sun, 24 Nov 2024 13:18:49 +0900 Subject: [PATCH] Implement StoppableTasklet#stop(StepExecution) in SystemCommandTasklet --- .../step/tasklet/SystemCommandTasklet.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SystemCommandTasklet.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SystemCommandTasklet.java index 4499279e8e..1fd8ecc7ab 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SystemCommandTasklet.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SystemCommandTasklet.java @@ -61,6 +61,7 @@ * @author Will Schipp * @author Mahmoud Ben Hassine * @author Injae Kim + * @author Hyunsang Han */ public class SystemCommandTasklet implements StepExecutionListener, StoppableTasklet, InitializingBean { @@ -275,4 +276,21 @@ public void stop() { stopped = true; } + /** + * Interrupts the execution of the system command if the given {@link StepExecution} + * matches the current execution context. This method allows for granular control over + * stopping specific step executions, ensuring that only the intended command is halted. + * + * @param stepExecution the current {@link StepExecution} context; the execution is + * interrupted if it matches the ongoing one. + * @since 6.0 + * @see StoppableTasklet#stop(StepExecution) + */ + @Override + public void stop(StepExecution stepExecution) { + if (stepExecution.equals(execution)) { + stopped = true; + } + } + }