Class DelegatingExecutor

  • All Implemented Interfaces:
    Executor, org.springframework.core.task.AsyncListenableTaskExecutor, org.springframework.core.task.AsyncTaskExecutor, org.springframework.core.task.TaskExecutor, org.springframework.scheduling.SchedulingTaskExecutor

    public class DelegatingExecutor
    extends Object
    implements org.springframework.core.task.AsyncListenableTaskExecutor, org.springframework.scheduling.SchedulingTaskExecutor
    Task executor that delegates to the task executor configured for a task.

    In addition to the delegate, the async configuration properties and the task name is stored, so we know which task this executor is for and we are able to determine the timeout.

    Since:
    2.0.0
    Author:
    Rutger Lubbers, Paul Klos
    • Constructor Detail

      • DelegatingExecutor

        public DelegatingExecutor​(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor delegate,
                                  ExecutorConfigurationProperties executorConfigurationProperties,
                                  Collection<TaskListenerFactory> taskListenerFactories,
                                  String taskName)
        Constructor.
        Parameters:
        delegate - the delegate
        executorConfigurationProperties - the configuration properties
        taskListenerFactories - The task context providers.
        taskName - the task name
    • Method Detail

      • execute

        public void execute​(@NonNull
                            Runnable task)

        Configures a SharedTaskContextHolder before delegating execution.

        Specified by:
        execute in interface Executor
        Specified by:
        execute in interface org.springframework.core.task.TaskExecutor
      • execute

        public void execute​(@NonNull
                            Runnable task,
                            long startTimeout)

        Configures a SharedTaskContextHolder before delegating execution.

        Specified by:
        execute in interface org.springframework.core.task.AsyncTaskExecutor
      • submit

        public Future<?> submit​(@NonNull
                                Runnable task)

        Configures a SharedTaskContextHolder before delegating execution.

        Specified by:
        submit in interface org.springframework.core.task.AsyncTaskExecutor
      • submit

        public <T> Future<T> submit​(@NonNull
                                    Callable<T> task)

        Configures a SharedTaskContextHolder before delegating execution.

        Specified by:
        submit in interface org.springframework.core.task.AsyncTaskExecutor
      • submitListenable

        public org.springframework.util.concurrent.ListenableFuture<?> submitListenable​(Runnable task)

        Configures a SharedTaskContextHolder before delegating execution.

        Specified by:
        submitListenable in interface org.springframework.core.task.AsyncListenableTaskExecutor
      • submitListenable

        public <T> org.springframework.util.concurrent.ListenableFuture<T> submitListenable​(@NotNull
                                                                                            @NotNull Callable<T> task)

        Configures a SharedTaskContextHolder before delegating execution.

        Specified by:
        submitListenable in interface org.springframework.core.task.AsyncListenableTaskExecutor
      • getExecutorStatistics

        public ExecutorStatisticsView getExecutorStatistics()
        Return the view on the statistics.
      • hasDelegate

        public boolean hasDelegate​(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor executor)
        For testing purposes.
      • getActiveCount

        public int getActiveCount()
        For testing purposes.
      • prefersShortLivedTasks

        public boolean prefersShortLivedTasks()
        Specified by:
        prefersShortLivedTasks in interface org.springframework.scheduling.SchedulingTaskExecutor