Interface OSThread

All Known Implementing Classes:
AbstractOSThread, AixOSThread, FreeBsdOSThread, LinuxOSThread, MacOSThread, SolarisOSThread, WindowsOSThread

public interface OSThread
Represents a Thread/Task on the operating system.
  • Method Summary

    Modifier and Type Method Description
    long getContextSwitches()
    A snapshot of the context switches the thread has done.
    long getKernelTime()
    Kernel (privileged) time used by the thread.
    long getMajorFaults()
    The number of major (hard) faults the thread has made which have required loading a memory page from disk.
    long getMinorFaults()
    The number of minor (soft) faults the thread has made which have not required loading a memory page from disk.
    java.lang.String getName()
    The name of the thread.
    int getOwningProcessId()
    The owning process of this thread.
    int getPriority()
    Priority of the thread, the meaning of which is dependent on the OS.
    long getStartMemoryAddress()
    The memory address above which this thread can run.
    long getStartTime()
    The start time of the thread.
    OSProcess.State getState()
    Getter for the field state.
    double getThreadCpuLoadBetweenTicks​(OSThread thread)
    Gets CPU usage of this thread since a previous snapshot of the same thread, provided as a parameter.
    double getThreadCpuLoadCumulative()
    Gets cumulative CPU usage of this thread.
    int getThreadId()
    The thread id.
    long getUpTime()
    Elapsed/up-time of the thread.
    long getUserTime()
    User time used by the thread.
    boolean updateAttributes()
    Attempts to updates process attributes.
  • Method Details

    • getThreadId

      int getThreadId()
      The thread id. The meaning of this value is OS-dependent.
      Returns:
      Returns the id of the thread.
    • getName

      java.lang.String getName()
      The name of the thread. Presence of a name is operating-system dependent and may include information (such as an index of running threads) that changes during execution.
      Returns:
      Returns the name of the task/thread.
    • getState

      OSProcess.State getState()

      Getter for the field state.

      Returns:
      Returns the execution state of the task/thread.
    • getThreadCpuLoadCumulative

      double getThreadCpuLoadCumulative()
      Gets cumulative CPU usage of this thread.
      Returns:
      The proportion of up time that the thread was executing in kernel or user mode.
    • getThreadCpuLoadBetweenTicks

      double getThreadCpuLoadBetweenTicks​(OSThread thread)
      Gets CPU usage of this thread since a previous snapshot of the same thread, provided as a parameter.
      Parameters:
      thread - An OSThread object containing statistics for this same thread collected at a prior point in time. May be null.
      Returns:
      If the prior snapshot is for the same thread at a prior point in time, the proportion of elapsed up time between the current thread snapshot and the previous one that the thread was executing in kernel or user mode. Returns cumulative load otherwise.
    • getOwningProcessId

      int getOwningProcessId()
      The owning process of this thread. For single-threaded processes, the owning process ID may be the same as the thread's ID.
      Returns:
      The owning process of this thread.
    • getStartMemoryAddress

      long getStartMemoryAddress()
      The memory address above which this thread can run.
      Returns:
      The start address.
    • getContextSwitches

      long getContextSwitches()
      A snapshot of the context switches the thread has done. Since the context switches could be voluntary and non-voluntary, this gives the sum of both.
      Returns:
      sum of both voluntary and involuntary context switches.
    • getMinorFaults

      long getMinorFaults()
      The number of minor (soft) faults the thread has made which have not required loading a memory page from disk. Sometimes called reclaims. Linux only.
      Returns:
      minor faults.
    • getMajorFaults

      long getMajorFaults()
      The number of major (hard) faults the thread has made which have required loading a memory page from disk. Linux only.
      Returns:
      major faults.
    • getKernelTime

      long getKernelTime()
      Kernel (privileged) time used by the thread.
      Returns:
      Returns the number of milliseconds the task/thread has executed in kernel/system mode.
    • getUserTime

      long getUserTime()
      User time used by the thread.
      Returns:
      Returns the number of milliseconds the task/thread has executed in user mode.
    • getUpTime

      long getUpTime()
      Elapsed/up-time of the thread.
      Returns:
      Returns the number of milliseconds since the task/thread started.
    • getStartTime

      long getStartTime()
      The start time of the thread.
      Returns:
      Returns the start time of the task/thread in number of milliseconds since January 1, 1970.
    • getPriority

      int getPriority()
      Priority of the thread, the meaning of which is dependent on the OS.
      Returns:
      priority.
    • updateAttributes

      boolean updateAttributes()
      Attempts to updates process attributes. Returns false if the update fails, which will occur if the process no longer exists. Not implemented for macOS, as thread ID is simply an index and not unique.
      Returns:
      true if the update was successful, false if the update failed. In addition, on a failed update the thread state will be changed to OSProcess.State.INVALID.