com.h3c.util.concurrent

## Class LoggerThreadListener

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

- All Implemented Interfaces:
    ThreadMonitor.ThreadListener

      public class LoggerThreadListener
      extends Object
      implements ThreadMonitor.ThreadListener

  Thread listener that writes the state to log files.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `LoggerThreadListener(String threadIdPrefix, org.slf4j.Logger logger, javax.measure.Measurable<javax.measure.quantity.Duration> executionDurationThreshold)` Creates a new `ThreadMonitor.ThreadListener`.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `executing(Collection<ThreadMonitor.ThreadExecutionState> states)` Callback method to notify a snapshot of the active threads in execution.
    `void` | `failed(ThreadMonitor.ThreadExecutionState state, Exception failure)` Callback method to notify a thread has failed and the exception was not caught.
    `void` | `finished(ThreadMonitor.ThreadExecutionState state)` Callback method to notify a thread has finished execution.
    `void` | `overlapped(ThreadMonitor.ThreadExecutionState state, javax.measure.Measurable<javax.measure.quantity.Duration> period)` Callback method to notify when a `Runnable` is submitted to be executed at a fixed rate but it took more time to execute than its period.
    `void` | `started(ThreadMonitor.ThreadExecutionState state)` Callback method to notify a thread has started execution.

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

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

- - ### Constructor Detail

    - #### LoggerThreadListener

          public LoggerThreadListener(String threadIdPrefix,
                              org.slf4j.Logger logger,
                              javax.measure.Measurable<javax.measure.quantity.Duration> executionDurationThreshold)

      Creates a new `ThreadMonitor.ThreadListener`.
      Parameters:
        `threadIdPrefix` - a prefix for the thread Id used as a convenient way of identifying logs associated to thread monitoring. For example, using "th-" as `threadIdPrefix` would produce logs messages starting with "th-1" for the first executed thread.
        `logger` - logger used to write threads state
        `executionDurationThreshold` - when a thread takes more time in execution state than `executionDurationThreshold` a warning log will be created.

  - ### Method Detail

    - #### started

          public void started(ThreadMonitor.ThreadExecutionState state)

      Description copied from interface: `ThreadMonitor.ThreadListener`
      Callback method to notify a thread has started execution.

      Note: ThreadExecutionState's end time is updated by the executing thread, so by the moment the state is processed the thread might have finished execution.

      Specified by:
        `started` in interface `ThreadMonitor.ThreadListener`
      Parameters:
        `state` - thread execution state

    - #### finished

          public void finished(ThreadMonitor.ThreadExecutionState state)

      Description copied from interface: `ThreadMonitor.ThreadListener`
      Callback method to notify a thread has finished execution. This method could be used to track threads that take too long to execute.
      Specified by:
        `finished` in interface `ThreadMonitor.ThreadListener`
      Parameters:
        `state` - thread execution state

    - #### executing

          public void executing(Collection<ThreadMonitor.ThreadExecutionState> states)

      Description copied from interface: `ThreadMonitor.ThreadListener`
      Callback method to notify a snapshot of the active threads in execution. This method could be used to track threads spending too long in execution state (Potentially in deadlock).

      Note: ThreadExecutionState's end time is updated by the executing thread, so by the moment the state is processed the thread might have finished execution.

      Specified by:
        `executing` in interface `ThreadMonitor.ThreadListener`
      Parameters:
        `states` - threads execution states

    - #### overlapped

          public void overlapped(ThreadMonitor.ThreadExecutionState state,
                        javax.measure.Measurable<javax.measure.quantity.Duration> period)

      Description copied from interface: `ThreadMonitor.ThreadListener`
      Callback method to notify when a `Runnable` is submitted to be executed at a fixed rate but it took more time to execute than its period.
      Specified by:
        `overlapped` in interface `ThreadMonitor.ThreadListener`
      Parameters:
        `state` - thread execution state
        `period` - period the `Runnable` was scheduled with.

    - #### failed

          public void failed(ThreadMonitor.ThreadExecutionState state,
                    Exception failure)

      Description copied from interface: `ThreadMonitor.ThreadListener`
      Callback method to notify a thread has failed and the exception was not caught.
      Specified by:
        `failed` in interface `ThreadMonitor.ThreadListener`
      Parameters:
        `state` - thread execution state
        `failure` - failure

Copyright © 2014. All Rights Reserved.