org.springframework.scheduling.concurrent

Class ConcurrentTaskExecutor

  • java.lang.Object
    • org.springframework.scheduling.concurrent.ConcurrentTaskExecutor
    • Constructor Summary

      Constructors 
      Constructor and Description
      ConcurrentTaskExecutor()
      Create a new ConcurrentTaskExecutor, using a single thread executor as default.
      ConcurrentTaskExecutor(java.util.concurrent.Executor executor)
      Create a new ConcurrentTaskExecutor, using the given Executor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      void execute(java.lang.Runnable task)
      Execute the given task.
      void execute(java.lang.Runnable task, long startTimeout)
      Execute the given task.
      java.util.concurrent.Executor getConcurrentExecutor()
      Return the Executor that this adapter delegates to.
      void setConcurrentExecutor(java.util.concurrent.Executor executor)
      Specify the Executor to delegate to.
      void setTaskDecorator(TaskDecorator taskDecorator)
      Specify a custom TaskDecorator to be applied to any Runnable about to be executed.
      <T> java.util.concurrent.Future<T> submit(java.util.concurrent.Callable<T> task)
      Submit a Callable task for execution, receiving a Future representing that task.
      java.util.concurrent.Future<?> submit(java.lang.Runnable task)
      Submit a Runnable task for execution, receiving a Future representing that task.
      <T> ListenableFuture<T> submitListenable(java.util.concurrent.Callable<T> task)
      Submit a Callable task for execution, receiving a ListenableFuture representing that task.
      ListenableFuture<?> submitListenable(java.lang.Runnable task)
      Submit a Runnable task for execution, receiving a ListenableFuture representing that task.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ConcurrentTaskExecutor

        public ConcurrentTaskExecutor()
        Create a new ConcurrentTaskExecutor, using a single thread executor as default.
        See Also:
        Executors.newSingleThreadExecutor()
      • ConcurrentTaskExecutor

        public ConcurrentTaskExecutor(@Nullable
                                      java.util.concurrent.Executor executor)
        Create a new ConcurrentTaskExecutor, using the given Executor.

        Autodetects a JSR-236 ManagedExecutorService in order to expose ManagedTask adapters for it.

        Parameters:
        executor - the Executor to delegate to
    • Method Detail

      • setConcurrentExecutor

        public final void setConcurrentExecutor(@Nullable
                                                java.util.concurrent.Executor executor)
        Specify the Executor to delegate to.

        Autodetects a JSR-236 ManagedExecutorService in order to expose ManagedTask adapters for it.

      • getConcurrentExecutor

        public final java.util.concurrent.Executor getConcurrentExecutor()
        Return the Executor that this adapter delegates to.
      • setTaskDecorator

        public final void setTaskDecorator(TaskDecorator taskDecorator)
        Specify a custom TaskDecorator to be applied to any Runnable about to be executed.

        Note that such a decorator is not necessarily being applied to the user-supplied Runnable/Callable but rather to the actual execution callback (which may be a wrapper around the user-supplied task).

        The primary use case is to set some execution context around the task's invocation, or to provide some monitoring/statistics for task execution.

        Since:
        4.3
      • execute

        public void execute(java.lang.Runnable task)
        Description copied from interface: TaskExecutor
        Execute the given task.

        The call might return immediately if the implementation uses an asynchronous execution strategy, or might block in the case of synchronous execution.

        Specified by:
        execute in interface java.util.concurrent.Executor
        Specified by:
        execute in interface TaskExecutor
        Parameters:
        task - the Runnable to execute (never null)
      • submit

        public java.util.concurrent.Future<?> submit(java.lang.Runnable task)
        Description copied from interface: AsyncTaskExecutor
        Submit a Runnable task for execution, receiving a Future representing that task. The Future will return a null result upon completion.
        Specified by:
        submit in interface AsyncTaskExecutor
        Parameters:
        task - the Runnable to execute (never null)
        Returns:
        a Future representing pending completion of the task
      • submit

        public <T> java.util.concurrent.Future<T> submit(java.util.concurrent.Callable<T> task)
        Description copied from interface: AsyncTaskExecutor
        Submit a Callable task for execution, receiving a Future representing that task. The Future will return the Callable's result upon completion.
        Specified by:
        submit in interface AsyncTaskExecutor
        Parameters:
        task - the Callable to execute (never null)
        Returns:
        a Future representing pending completion of the task
      • submitListenable

        public ListenableFuture<?> submitListenable(java.lang.Runnable task)
        Description copied from interface: AsyncListenableTaskExecutor
        Submit a Runnable task for execution, receiving a ListenableFuture representing that task. The Future will return a null result upon completion.
        Specified by:
        submitListenable in interface AsyncListenableTaskExecutor
        Parameters:
        task - the Runnable to execute (never null)
        Returns:
        a ListenableFuture representing pending completion of the task
      • submitListenable

        public <T> ListenableFuture<T> submitListenable(java.util.concurrent.Callable<T> task)
        Description copied from interface: AsyncListenableTaskExecutor
        Submit a Callable task for execution, receiving a ListenableFuture representing that task. The Future will return the Callable's result upon completion.
        Specified by:
        submitListenable in interface AsyncListenableTaskExecutor
        Parameters:
        task - the Callable to execute (never null)
        Returns:
        a ListenableFuture representing pending completion of the task