File tree Expand file tree Collapse file tree 3 files changed +44
-1
lines changed
spring-batch-core/src/main/java/org/springframework/batch/core Expand file tree Collapse file tree 3 files changed +44
-1
lines changed Original file line number Diff line number Diff line change 3636import org .springframework .batch .core .job .parameters .JobParametersIncrementer ;
3737import org .springframework .batch .core .job .parameters .JobParametersInvalidException ;
3838import org .springframework .batch .core .step .Step ;
39+ import org .springframework .batch .core .step .StoppableStep ;
3940import org .springframework .batch .core .step .StepExecution ;
4041import org .springframework .batch .core .job .UnexpectedJobExecutionException ;
4142import org .springframework .batch .core .configuration .JobRegistry ;
@@ -351,6 +352,11 @@ public boolean stop(JobExecution jobExecution) throws JobExecutionNotRunningExce
351352 StepSynchronizationManager .release ();
352353 }
353354 }
355+ if (step instanceof StoppableStep stoppableStep ) {
356+ StepSynchronizationManager .register (stepExecution );
357+ stoppableStep .stop (stepExecution );
358+ StepSynchronizationManager .release ();
359+ }
354360 }
355361 catch (NoSuchStepException e ) {
356362 logger .warn ("Step not found" , e );
Original file line number Diff line number Diff line change 6363 * @author Mahmoud Ben Hassine
6464 * @author Jinwoo Bae
6565 */
66- public abstract class AbstractStep implements Step , InitializingBean , BeanNameAware {
66+ public abstract class AbstractStep implements StoppableStep , InitializingBean , BeanNameAware {
6767
6868 private static final Log logger = LogFactory .getLog (AbstractStep .class );
6969
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2025-present the original author or authors.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * https://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+ package org .springframework .batch .core .step ;
17+
18+ /**
19+ * Extension of the {@link Step} interface to be implemented by steps that support being
20+ * stopped.
21+ *
22+ * @author Mahmoud Ben Hassine
23+ * @since 6.0
24+ */
25+ public interface StoppableStep extends Step {
26+
27+ /**
28+ * Callback to signal the step to stop. The default implementation sets the
29+ * {@link StepExecution} to terminate only. Concrete implementations can override this
30+ * method to add custom stop logic.
31+ * @param stepExecution the current step execution
32+ */
33+ default void stop (StepExecution stepExecution ) {
34+ stepExecution .setTerminateOnly ();
35+ }
36+
37+ }
You can’t perform that action at this time.
0 commit comments