public class TaskService extends AbstractBean
Methods descriptions are copied from ExecutorService
Constructor and Description |
---|
TaskService(String name)
Creates a new
TaskService with default executor. |
TaskService(String name,
ExecutorService executorService)
Creates a new
TaskService |
Modifier and Type | Method and Description |
---|---|
boolean |
awaitTermination(long timeout,
TimeUnit unit)
Blocks until all tasks have completed execution after a shutdown
request, or the timeout occurs, or the current thread is
interrupted, whichever happens first.
|
void |
execute(Task task)
Executes the task.
|
String |
getName()
Gets the name of this task service
|
List<Task> |
getTasks()
Returns the list of tasks which are executing by this service
|
boolean |
isShutdown()
Returns true if this executor has been shut down.
|
boolean |
isTerminated()
Returns true if all tasks have completed following shut down.
|
void |
shutdown()
Initiates an orderly shutdown in which previously submitted
tasks are executed, but no new tasks will be accepted.
|
List<Runnable> |
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.
|
addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
public TaskService(String name, ExecutorService executorService)
TaskService
name
- the name of the task serviceexecutorService
- the executor to be used to run tasks.public TaskService(String name)
TaskService
with default executor.
The default executor is a ThreadPoolExecutor with core pool size = 3,
maximum pool size = 10, threads live time = 1 second and queue of type
LinkedBlockingQueue
.public final String getName()
public void execute(Task task)
task
- the task to be executedpublic List<Task> getTasks()
public final void shutdown()
SecurityException
- if a security manager exists and
shutting down this ExecutorService may manipulate
threads that the caller is not permitted to modify
because it does not hold RuntimePermission
("modifyThread"),
or the security manager's checkAccess method
denies access.public final List<Runnable> shutdownNow()
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.
SecurityException
- if a security manager exists and
shutting down this ExecutorService may manipulate
threads that the caller is not permitted to modify
because it does not hold RuntimePermission
("modifyThread"),
or the security manager's checkAccess method
denies access.public final boolean isShutdown()
public final boolean isTerminated()
public final boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException
timeout
- the maximum time to waitunit
- the time unit of the timeout argumentInterruptedException
- if interrupted while waitingCopyright © 2009–2019. All rights reserved.