View Javadoc
1   /*
2    * Copyright 2002-2013 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    *      http://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  
17  package org.springframework.scheduling;
18  
19  import org.springframework.core.task.AsyncTaskExecutor;
20  
21  /**
22   * A {@link org.springframework.core.task.TaskExecutor} extension exposing
23   * scheduling characteristics that are relevant to potential task submitters.
24   *
25   * <p>Scheduling clients are encouraged to submit
26   * {@link Runnable Runnables} that match the exposed preferences
27   * of the {@code TaskExecutor} implementation in use.
28   *
29   * <p>Note: {@link SchedulingTaskExecutor} implementations are encouraged to also
30   * implement the {@link org.springframework.core.task.AsyncListenableTaskExecutor}
31   * interface. This is not required due to the dependency on Spring 4.0's new
32   * {@link org.springframework.util.concurrent.ListenableFuture} interface,
33   * which would make it impossible for third-party executor implementations
34   * to remain compatible with both Spring 4.0 and Spring 3.x.
35   *
36   * @author Juergen Hoeller
37   * @since 2.0
38   * @see SchedulingAwareRunnable
39   * @see org.springframework.core.task.TaskExecutor
40   * @see org.springframework.scheduling.commonj.WorkManagerTaskExecutor
41   */
42  public interface SchedulingTaskExecutor extends AsyncTaskExecutor {
43  
44  	/**
45  	 * Does this {@code TaskExecutor} prefer short-lived tasks over
46  	 * long-lived tasks?
47  	 * <p>A {@code SchedulingTaskExecutor} implementation can indicate
48  	 * whether it prefers submitted tasks to perform as little work as they
49  	 * can within a single task execution. For example, submitted tasks
50  	 * might break a repeated loop into individual subtasks which submit a
51  	 * follow-up task afterwards (if feasible).
52  	 * <p>This should be considered a hint. Of course {@code TaskExecutor}
53  	 * clients are free to ignore this flag and hence the
54  	 * {@code SchedulingTaskExecutor} interface overall. However, thread
55  	 * pools will usually indicated a preference for short-lived tasks, to be
56  	 * able to perform more fine-grained scheduling.
57  	 * @return {@code true} if this {@code TaskExecutor} prefers
58  	 * short-lived tasks
59  	 */
60  	boolean prefersShortLivedTasks();
61  
62  }