001/*
002 * Copyright 2013 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.springframework.batch.core.step.tasklet;
017
018import org.springframework.batch.core.launch.JobOperator;
019
020/**
021 * An extension to the {@link Tasklet} interface to allow users to
022 * add logic for stopping a tasklet.  It is up to each implementation
023 * as to how the stop will behave.  The only guarantee provided by the
024 * framework is that a call to {@link JobOperator#stop(long)} will
025 * attempt to call the stop method on any currently running
026 * StoppableTasklet.  The call to {@link StoppableTasklet#stop()} will
027 * be from a thread other than the thread executing {@link org.springframework.batch.core.step.tasklet.Tasklet#execute(org.springframework.batch.core.StepContribution, org.springframework.batch.core.scope.context.ChunkContext)}
028 * so the appropriate thread safety and visibility controls should be
029 * put in place.
030 *
031 * @author Will Schipp
032 * @since 3.0
033 */
034public interface StoppableTasklet extends Tasklet {
035
036        /**
037         * Used to signal that the job this {@link Tasklet} is executing
038         * within has been requested to stop.
039         */
040        void stop();
041}