Class CPUTimeCollector

java.lang.Object
org.jppf.utils.concurrent.ThreadSynchronization
org.jppf.management.diagnostics.CPUTimeCollector
All Implemented Interfaces:
Runnable

public final class CPUTimeCollector extends ThreadSynchronization implements Runnable
This class computes, at regular intervals, the approximative value of the CPU load for the current JVM.

The computed value is equal to sumi(thread_used_cpui) / interval, for all the live threads of the JVM at the time of the computation.

Thus, errors may occur, since many threads may have been created then died between two computations. However, in most cases this is a reasonable approximation, whose computation does not tax the CPU too heavily.

Author:
Laurent Cohen
  • Field Details

    • INTERVAL

      protected static long INTERVAL
      The interval between two computations in milliseconds. Taken from the value of configuration property "jppf.cpu.load.compuation.interval". It defaults to 1000 (1 second) if the property is unspecified.
  • Method Details

    • run

      public void run()
      Specified by:
      run in interface Runnable
    • getLoad

      public double getLoad()
      Get the CPU load as the ratio of totalCpuTime / computationInterval.
      Returns:
      the CPU load as a double value in the range [0, 1].
    • getInstance

      public static CPUTimeCollector getInstance()
      Returns:
      the singleton instance of this class.