Class TaskService


  • public class TaskService
    extends AbstractBean
    The service for executing tasks

    Methods descriptions are copied from ExecutorService

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String DEFAULT_NAME  
    • Constructor Summary

      Constructors 
      Constructor Description
      TaskService​(java.lang.String name)
      Creates a new TaskService with default executor.
      TaskService​(java.lang.String name, java.util.concurrent.ExecutorService executorService)
      Creates a new TaskService
    • Constructor Detail

      • TaskService

        public TaskService​(java.lang.String name,
                           java.util.concurrent.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​(java.lang.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 Detail

      • getName

        public final java.lang.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 java.util.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:
        java.lang.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 java.util.List<java.lang.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:
        java.lang.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,
                                              java.util.concurrent.TimeUnit unit)
                                       throws java.lang.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:
        java.lang.InterruptedException - if interrupted while waiting