Package org.jdesktop.application
Class TaskService
java.lang.Object
org.jdesktop.application.AbstractBean
org.jdesktop.application.TaskService
The service for executing tasks
Methods descriptions are copied from ExecutorService
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTaskService(String name) Creates a newTaskServicewith default executor.TaskService(String name, ExecutorService executorService) Creates a newTaskService -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanawaitTermination(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.voidExecutes the task.final StringgetName()Gets the name of this task servicegetTasks()Returns the list of tasks which are executing by this servicefinal booleanReturns true if this executor has been shut down.final booleanReturns true if all tasks have completed following shut down.final voidshutdown()Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.Methods inherited from class org.jdesktop.application.AbstractBean
addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
Field Details
-
DEFAULT_NAME
- See Also:
-
-
Constructor Details
-
TaskService
Creates a newTaskService- Parameters:
name- the name of the task serviceexecutorService- the executor to be used to run tasks.
-
TaskService
Creates a newTaskServicewith 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 typeLinkedBlockingQueue.
-
-
Method Details
-
getName
Gets the name of this task service- Returns:
- this task service's name
-
execute
Executes the task.- Parameters:
task- the task to be executed
-
getTasks
Returns the list of tasks which are executing by this service- Returns:
- the list of tasks which are executing by this service
-
shutdown
public final void 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.- Throws:
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 holdRuntimePermission("modifyThread"), or the security manager's checkAccess method denies access.
-
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.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 of tasks that never commenced execution
- Throws:
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 holdRuntimePermission("modifyThread"), or the security manager's checkAccess method denies access.
-
isShutdown
public final boolean isShutdown()Returns true if this executor has been shut down.- Returns:
- true if this executor has been shut down
-
isTerminated
public final boolean 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:
- true if all tasks have completed following shut down
-
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- the maximum time to waitunit- the time unit of the timeout argument- Returns:
- true if this executor terminated and false if the timeout elapsed before termination
- Throws:
InterruptedException- if interrupted while waiting
-