com.h3c.util.concurrent

## Class DefaultThreadExecutor

- java.lang.Object
- - com.h3c.util.concurrent.DefaultThreadExecutor

- All Implemented Interfaces:
    CallableExecutor, RunnableExecutor, ThreadExecutor

      public class DefaultThreadExecutor
      extends Object
      implements ThreadExecutor

  Thread executor implementation. This class needs to implements ExclusiveTaskExecutorService instead of TaskExclusiveService to expose shutdown method.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `DefaultThreadExecutor()` Creates a new task executor.
    `DefaultThreadExecutor(String threadPoolName, int corePoolSize, int maximumPoolSize, int scheduleCorePoolSize)` Creates a new task executor with fixed thread pool size.
    `DefaultThreadExecutor(ThreadPoolExecutor executor, ScheduledExecutorService scheduledExecutor)` Creates a new task executor.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `<T> ScheduledFuture<T>` | `schedule(Callable<T> task, javax.measure.Measurable<javax.measure.quantity.Duration> delay)` Creates and executes a ScheduledFuture that becomes enabled after the given delay.
    `ScheduledFuture<?>` | `schedule(Runnable task, javax.measure.Measurable<javax.measure.quantity.Duration> delay)` Creates and executes a ScheduledFuture that becomes enabled after the given delay.
    `ScheduledFuture<?>` | `scheduleAtFixedRate(Runnable task, Date initialTime, javax.measure.Measurable<javax.measure.quantity.Duration> period)` For the sake of cancellability but not provide a usable result Creates and executes a periodic action that becomes enabled first at the given initial time, and subsequently with the given period; that is executions will commence at initialTime then initialTime+period, then initialTime + 2 * period, and so on.
    `ScheduledFuture<?>` | `scheduleAtFixedRate(Runnable task, javax.measure.Measurable<javax.measure.quantity.Duration> initialDelay, javax.measure.Measurable<javax.measure.quantity.Duration> period)` Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is executions will commence after initialDelay then initialDelay+period, then initialDelay + 2 * period, and so on.
    `ScheduledFuture<?>` | `scheduleWithFixedDelay(Runnable task, javax.measure.Measurable<javax.measure.quantity.Duration> initialDelay, javax.measure.Measurable<javax.measure.quantity.Duration> delay)` Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given delay between the termination of one execution and the commencement of the next.
    `void` | `shutdown()` Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.
    `<T> Future<T>` | `submit(Callable<T> task)` This method is used to decouple execution of task i.e.
    `Future<?>` | `submit(Runnable task)` This method is use to decouple execution of task i.e.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### DefaultThreadExecutor

          public DefaultThreadExecutor()

      Creates a new task executor.

    - #### DefaultThreadExecutor

          public DefaultThreadExecutor(String threadPoolName,
                               int corePoolSize,
                               int maximumPoolSize,
                               int scheduleCorePoolSize)

      Creates a new task executor with fixed thread pool size.
      Parameters:
        `threadPoolName` - thread pool name
        `corePoolSize` - the number of threads to keep in the pool, even if they are idle
        `maximumPoolSize` - the maximum number of threads to allow in the pool
        `scheduleCorePoolSize` - the number of schedule threads to keep in the pool, even if they are idle

    - #### DefaultThreadExecutor

          public DefaultThreadExecutor(ThreadPoolExecutor executor,
                               ScheduledExecutorService scheduledExecutor)

      Creates a new task executor.
      Parameters:
        `executor` - the executor to submit non-scheduled tasks
        `scheduledExecutor` - the executor to submit scheduled tasks

  - ### Method Detail

    - #### submit

          public Future<?> submit(Runnable task)

      Description copied from interface: `RunnableExecutor`
      This method is use to decouple execution of task i.e. to have a task executed in the context of a worker thread instead of in the context of the calling thread.
      Specified by:
        `submit` in interface `RunnableExecutor`
      Parameters:
        `task` - task to be executed
      Returns:
        a Future instance related to the result of the execution of the task.

    - #### submit

          public <T> Future<T> submit(Callable<T> task)

      Description copied from interface: `CallableExecutor`
      This method is used to decouple execution of task i.e. to have a task executed in the context of a worker thread instead of in the context of the calling thread.
      Specified by:
        `submit` in interface `CallableExecutor`
      Type Parameters:
        `T` - type of the execution result
      Parameters:
        `task` - task to be executed
      Returns:
        a Future instance related to the result of the execution of the task. Result can be retrieved via get method.

    - #### schedule

          public <T> ScheduledFuture<T> schedule(Callable<T> task,
                                        javax.measure.Measurable<javax.measure.quantity.Duration> delay)

      Description copied from interface: `ThreadExecutor`
      Creates and executes a ScheduledFuture that becomes enabled after the given delay.
      Specified by:
        `schedule` in interface `ThreadExecutor`
      Type Parameters:
        `T` - the type of the execution result
      Parameters:
        `task` - the task to be executed
        `delay` - the time from now to delay execution
      Returns:
        a future that can be used to extract result or cancel

    - #### schedule

          public ScheduledFuture<?> schedule(Runnable task,
                                    javax.measure.Measurable<javax.measure.quantity.Duration> delay)

      Description copied from interface: `ThreadExecutor`
      Creates and executes a ScheduledFuture that becomes enabled after the given delay.
      Specified by:
        `schedule` in interface `ThreadExecutor`
      Parameters:
        `task` - the runnable task to be executed
        `delay` - the time from now to delay execution
      Returns:
        a future that can be used to cancel

    - #### scheduleAtFixedRate

          public ScheduledFuture<?> scheduleAtFixedRate(Runnable task,
                                               javax.measure.Measurable<javax.measure.quantity.Duration> initialDelay,
                                               javax.measure.Measurable<javax.measure.quantity.Duration> period)

      Description copied from interface: `ThreadExecutor`
      Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is executions will commence after initialDelay then initialDelay+period, then initialDelay + 2 * period, and so on.
      Specified by:
        `scheduleAtFixedRate` in interface `ThreadExecutor`
      Parameters:
        `task` - the task to be executed
        `initialDelay` - the time to delay first execution
        `period` - the period between successive executions
      Returns:
        a future representing pending completion of the task, and whose get() method will throw an exception upon cancellation

    - #### scheduleAtFixedRate

          public ScheduledFuture<?> scheduleAtFixedRate(Runnable task,
                                               Date initialTime,
                                               javax.measure.Measurable<javax.measure.quantity.Duration> period)
                                                 throws IllegalArgumentException

      Description copied from interface: `ThreadExecutor`
      For the sake of cancellability but not provide a usable result Creates and executes a periodic action that becomes enabled first at the given initial time, and subsequently with the given period; that is executions will commence at initialTime then initialTime+period, then initialTime + 2 * period, and so on.
      Specified by:
        `scheduleAtFixedRate` in interface `ThreadExecutor`
      Parameters:
        `task` - the task to be executed
        `initialTime` - the time of the first execution
        `period` - the period between successive executions
      Returns:
        a future representing pending completion of the task, and whose get() method will throw an exception upon cancellation
      Throws:
        `IllegalArgumentException` - if initialTime is in the past

    - #### scheduleWithFixedDelay

          public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task,
                                                  javax.measure.Measurable<javax.measure.quantity.Duration> initialDelay,
                                                  javax.measure.Measurable<javax.measure.quantity.Duration> delay)

      Description copied from interface: `ThreadExecutor`
      Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given delay between the termination of one execution and the commencement of the next.
      Specified by:
        `scheduleWithFixedDelay` in interface `ThreadExecutor`
      Parameters:
        `task` - the task to be executed
        `initialDelay` - the time to delay first execution.
        `delay` - the delay between the termination of one execution and the commencement of the next
      Returns:
        a future representing pending completion of the task, and whose get() method will throw an exception upon cancellation

    - #### shutdown

          public 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. This method does not wait for previously submitted tasks to complete execution.

Copyright © 2014. All Rights Reserved.