001/* 002 * Copyright 2002-2018 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 long-lived tasks? 046 * <p>A {@code SchedulingTaskExecutor} implementation can indicate whether it 047 * prefers submitted tasks to perform as little work as they can within a single 048 * task execution. For example, submitted tasks might break a repeated loop into 049 * individual subtasks which submit a follow-up task afterwards (if feasible). 050 * <p>This should be considered a hint. Of course {@code TaskExecutor} clients 051 * are free to ignore this flag and hence the {@code SchedulingTaskExecutor} 052 * interface overall. However, thread pools will usually indicated a preference 053 * for short-lived tasks, allowing for more fine-grained scheduling. 054 * @return {@code true} if this executor prefers short-lived tasks (the default), 055 * {@code false} otherwise (for treatment like a regular {@code TaskExecutor}) 056 */ 057 default boolean prefersShortLivedTasks() { 058 return true; 059 } 060 061}