001/*
002 * Copyright 2002-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 */
016
017package org.springframework.scheduling;
018
019import org.springframework.core.task.AsyncTaskExecutor;
020
021/**
022 * A {@link org.springframework.core.task.TaskExecutor} extension exposing
023 * scheduling characteristics that are relevant to potential task submitters.
024 *
025 * <p>Scheduling clients are encouraged to submit
026 * {@link Runnable Runnables} that match the exposed preferences
027 * of the {@code TaskExecutor} implementation in use.
028 *
029 * <p>Note: {@link SchedulingTaskExecutor} implementations are encouraged to also
030 * implement the {@link org.springframework.core.task.AsyncListenableTaskExecutor}
031 * interface. This is not required due to the dependency on Spring 4.0's new
032 * {@link org.springframework.util.concurrent.ListenableFuture} interface,
033 * which would make it impossible for third-party executor implementations
034 * to remain compatible with both Spring 4.0 and Spring 3.x.
035 *
036 * @author Juergen Hoeller
037 * @since 2.0
038 * @see SchedulingAwareRunnable
039 * @see org.springframework.core.task.TaskExecutor
040 * @see org.springframework.scheduling.commonj.WorkManagerTaskExecutor
041 */
042public interface SchedulingTaskExecutor extends AsyncTaskExecutor {
043
044        /**
045         * Does this {@code TaskExecutor} prefer short-lived tasks over
046         * long-lived tasks?
047         * <p>A {@code SchedulingTaskExecutor} implementation can indicate
048         * whether it prefers submitted tasks to perform as little work as they
049         * can within a single task execution. For example, submitted tasks
050         * might break a repeated loop into individual subtasks which submit a
051         * follow-up task afterwards (if feasible).
052         * <p>This should be considered a hint. Of course {@code TaskExecutor}
053         * clients are free to ignore this flag and hence the
054         * {@code SchedulingTaskExecutor} interface overall. However, thread
055         * pools will usually indicated a preference for short-lived tasks, to be
056         * able to perform more fine-grained scheduling.
057         * @return {@code true} if this {@code TaskExecutor} prefers
058         * short-lived tasks
059         */
060        boolean prefersShortLivedTasks();
061
062}