Class TaskService

java.lang.Object
org.jdesktop.application.AbstractBean
org.jdesktop.application.TaskService

public class TaskService extends AbstractBean
The service for executing tasks

Methods descriptions are copied from ExecutorService

  • Field Details

  • Constructor Details

    • TaskService

      public TaskService(String name, ExecutorService executorService)
      Creates a new TaskService
      Parameters:
      name - the name of the task service
      executorService - the executor to be used to run tasks.
    • TaskService

      public TaskService(String name)
      Creates a new 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.
  • Method Details

    • getName

      public final String getName()
      Gets the name of this task service
      Returns:
      this task service's name
    • execute

      public void execute(Task task)
      Executes the task.
      Parameters:
      task - the task to be executed
    • getTasks

      public List<Task> 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 hold RuntimePermission("modifyThread"), or the security manager's checkAccess method denies access.
    • shutdownNow

      public final 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.

      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 hold RuntimePermission("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

      public final boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException
      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 wait
      unit - 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