com.h3c.util.concurrent

## Class ThreadMonitor

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

- All Implemented Interfaces:
    CallableExecutor, RunnableExecutor, ThreadExecutor

      public class ThreadMonitor
      extends Object
      implements ThreadExecutor

  `ThreadExecutor` proxy used to track threads. Its purpose is to be used for debugging at development phase, it should not be used at production code.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `ThreadMonitor.ThreadExecutionState` Thread execution state.
    `static interface` | `ThreadMonitor.ThreadListener` Thread listener.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ThreadMonitor(ThreadExecutor delegate, ThreadMonitor.ThreadListener threadListener, javax.measure.Measurable<javax.measure.quantity.Duration> activeThreadsStateUpdateFrequency)` Creates a new thread monitor.

  - ### 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.
    `<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

    - #### ThreadMonitor

          public ThreadMonitor(ThreadExecutor delegate,
                       ThreadMonitor.ThreadListener threadListener,
                       javax.measure.Measurable<javax.measure.quantity.Duration> activeThreadsStateUpdateFrequency)

      Creates a new thread monitor.
      Parameters:
        `delegate` - delegate
        `threadListener` - listener to handle thread monitoring, see `LoggerThreadListener`
        `activeThreadsStateUpdateFrequency` - frequency to update active threads state, `null` to not track active threads state at all. If `null` is used the executing() method in ThreadListener won't be called.

  - ### 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 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

    - #### 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

    - #### 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

Copyright © 2014. All Rights Reserved.