Top Description Fields Constructors Methods
org.springframework.core.task.support

public Class ExecutorServiceAdapter

extends AbstractExecutorService
Class Inheritance
Imports
java.util.List, java.util.concurrent.AbstractExecutorService, .TimeUnit, org.springframework.core.task.TaskExecutor, org.springframework.util.Assert

Adapter that takes a Spring org.springframework.core.task.TaskExecutor and exposes a full java.util.concurrent.ExecutorService for it.

This is primarily for adapting to client components that communicate via the java.util.concurrent.ExecutorService API. It can also be used as common ground between a local Spring TaskExecutor backend and a JNDI-located ManagedExecutorService in a Jakarta EE environment.

Note

This ExecutorService adapter does not support the lifecycle methods in the java.util.concurrent.ExecutorService API ("shutdown()" etc.), similar to a server-wide ManagedExecutorService in a Jakarta EE environment. The lifecycle is always up to the backend pool, with this adapter acting as an access-only proxy for that target pool.

Author
Juergen Hoeller
Since
3.0
See Also
java.util.concurrent.ExecutorService

Field Summary

Modifier and TypeField and Description
private final TaskExecutor

Constructor Summary

AccessConstructor and Description
public
ExecutorServiceAdapter(TaskExecutor
the target executor to delegate to
taskExecutor
)

Create a new ExecutorServiceAdapter, using the given target executor.

Method Summary

Modifier and TypeMethod and Description
public boolean
awaitTermination(long
the maximum time to wait
timeout
,
TimeUnit
the time unit of the timeout argument
unit
)

Implements java.util.concurrent.ExecutorService.awaitTermination.

Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.

public void
close()

Overrides default java.util.concurrent.ExecutorService.close.

Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.

public void
execute(Runnable
the runnable task
task
)

Implements java.util.concurrent.Executor.execute.

Executes the given command at some time in the future.

public boolean
isShutdown()

Implements java.util.concurrent.ExecutorService.isShutdown.

Returns true if this executor has been shut down.

public boolean
isTerminated()

Implements java.util.concurrent.ExecutorService.isTerminated.

Returns true if all tasks have completed following shut down.

public void
shutdown()

Implements java.util.concurrent.ExecutorService.shutdown.

Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.

public List<Runnable>
shutdownNow()

Implements java.util.concurrent.ExecutorService.shutdownNow.

Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.

Inherited from java.util.concurrent.AbstractExecutorService:
invokeAllinvokeAllinvokeAnyinvokeAnynewTaskFornewTaskForsubmitsubmitsubmit

Field Detail

taskExecutorback to summary
private final TaskExecutor taskExecutor

Constructor Detail

ExecutorServiceAdapterback to summary
public ExecutorServiceAdapter(TaskExecutor taskExecutor)

Create a new ExecutorServiceAdapter, using the given target executor.

Parameters
taskExecutor:TaskExecutor

the target executor to delegate to

Method Detail

awaitTerminationback to summary
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException

Implements java.util.concurrent.ExecutorService.awaitTermination.

Doc from java.util.concurrent.ExecutorService.awaitTermination.

Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.

Parameters
timeout:long

the maximum time to wait

unit:TimeUnit

the time unit of the timeout argument

Returns:boolean

true if this executor terminated and false if the timeout elapsed before termination

Annotations
@Override
Exceptions
InterruptedException:
if interrupted while waiting
closeback to summary
public void close()

Overrides default java.util.concurrent.ExecutorService.close.

Doc from java.util.concurrent.ExecutorService.close.

Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. This method waits until all tasks have completed execution and the executor has terminated.

If interrupted while waiting, this method stops all executing tasks as if by invoking shutdownNow(). It then continues to wait until all actively executing tasks have completed. Tasks that were awaiting execution are not executed. The interrupt status will be re-asserted before this method returns.

If already terminated, invoking this method has no effect.

executeback to summary
public void execute(Runnable task)

Implements java.util.concurrent.Executor.execute.

Doc from java.util.concurrent.Executor.execute.

Executes the given command at some time in the future. The command may execute in a new thread, in a pooled thread, or in the calling thread, at the discretion of the Executor implementation.

Parameters
task:Runnable

the runnable task

Annotations
@Override
isShutdownback to summary
public boolean isShutdown()

Implements java.util.concurrent.ExecutorService.isShutdown.

Doc from java.util.concurrent.ExecutorService.isShutdown.

Returns true if this executor has been shut down.

Returns:boolean

true if this executor has been shut down

Annotations
@Override
isTerminatedback to summary
public boolean isTerminated()

Implements java.util.concurrent.ExecutorService.isTerminated.

Doc from java.util.concurrent.ExecutorService.isTerminated.

Returns true if all tasks have completed following shut down. Note that isTerminated is never true unless either shutdown or shutdownNow was called first.

Returns:boolean

true if all tasks have completed following shut down

Annotations
@Override
shutdownback to summary
public void shutdown()

Implements java.util.concurrent.ExecutorService.shutdown.

Doc from java.util.concurrent.ExecutorService.shutdown.

Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. Invocation has no additional effect if already shut down.

This method does not wait for previously submitted tasks to complete execution. Use awaitTermination to do that.

Annotations
@Override
shutdownNowback to summary
public List<Runnable> shutdownNow()

Implements java.util.concurrent.ExecutorService.shutdownNow.

Doc from java.util.concurrent.ExecutorService.shutdownNow.

Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.

This method does not wait for actively executing tasks to terminate. Use awaitTermination to do that.

There are no guarantees beyond best-effort attempts to stop processing actively executing tasks. For example, typical implementations will cancel via Thread#interrupt, so any task that fails to respond to interrupts may never terminate.

Returns:List<Runnable>

list of tasks that never commenced execution

Annotations
@Override