public final class SyncTaskExecutor extends DelegatedTaskExecutorService implements MonitorableTaskExecutorService
execute or one of the submit
methods). Therefore whenever such execute or submit method
returns, the submitted task is already executed or never will be (due to the
executor being shut down).
There are two special instances which can be accessed through static methods:
getSimpleExecutor() for a simple and efficient
TaskExecutor instance which executes tasks synchronously on the
calling thread.
getDefaultInstance() to use as sensible
default values when an TaskExecutorService instance is needed.
TaskExecutorService instances, instances of
this class does not need to be shut down (but it is possible to do so).
wrappedExecutor| Constructor and Description |
|---|
SyncTaskExecutor()
Creates a new executor which executes tasks synchronously on the calling
thread.
|
| Modifier and Type | Method and Description |
|---|---|
static TaskExecutorService |
getDefaultInstance()
Returns an
TaskExecutorService which executes tasks synchronously
on the calling thread and cannot be shutted down. |
long |
getNumberOfExecutingTasks()
Returns the approximate number of tasks currently being executed.
|
long |
getNumberOfQueuedTasks()
Returns the approximate number of tasks currently queued to this
executor.
|
static TaskExecutor |
getSimpleExecutor()
Returns a plain and efficient
TaskExecutor which executes tasks
synchronously on the calling thread. |
boolean |
isExecutingInThis()
Returns
true if the calling code is executing in the context of
this executor. |
addTerminateListener, awaitTermination, execute, execute, executeFunction, executeStaged, isShutdown, isTerminated, shutdown, shutdownAndCancel, toString, tryAwaitTerminationclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitaddTerminateListener, awaitTermination, isShutdown, isTerminated, shutdown, shutdownAndCancel, tryAwaitTerminationexecute, execute, executeFunction, executeStagedpublic SyncTaskExecutor()
public static TaskExecutor getSimpleExecutor()
TaskExecutor which executes tasks
synchronously on the calling thread. This method always returns the same
executor instance and is considerably more efficient than a full-fledged
SyncTaskExecutor implementation (or the one returned by
getDefaultInstance().TaskExecutor which executes tasks
synchronously on the calling thread. This method never returns
null.public static TaskExecutorService getDefaultInstance()
TaskExecutorService which executes tasks synchronously
on the calling thread and cannot be shutted down. Attempting to shutdown
the returned TaskExecutorService will result in an unchecked
UnsupportedOperationException to be thrown.
This method always returns the same TaskExecutorService instance
and note that sharing the return value across multiple threads can cause
some synchronization overhead. So it is more efficient to create a new
instance when this is an issue. Therefore this
TaskExecutorService instance is only intended to be used as a
sensible default value.
TaskExecutorService which executes tasks synchronously
on the calling thread and cannot be shutted down. This method never
returns null and always returns the same instance.public long getNumberOfQueuedTasks()
Note that the value returned by this method should be considered unreliable and cannot be used for synchronization purposes.
Implementation note: This method always returns zero, since this executor never queues tasks.
getNumberOfQueuedTasks in interface MonitorableTaskExecutorpublic long getNumberOfExecutingTasks()
Note that the value returned by this method should be considered unreliable and cannot be used for synchronization purposes.
getNumberOfExecutingTasks in interface MonitorableTaskExecutorpublic boolean isExecutingInThis()
true if the calling code is executing in the context of
this executor. That is, it is executed by a task submitted to this
executor.
This method can be used to check that a method call is executing in the context it was designed for.
isExecutingInThis in interface ContextAwareTaskExecutortrue if the calling code is executing in the context of
this executor, false otherwise