Interface OSThread

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

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

    Nested Classes
    Modifier and Type
    Interface
    Description
    static final class 
    Constants which may be used to filter Thread lists
  • Method Summary

    Modifier and Type
    Method
    Description
    default long
    A snapshot of the context switches the thread has done.
    long
    Kernel (privileged) time used by the thread.
    default long
    The number of major (hard) faults the thread has made which have required loading a memory page from disk.
    default long
    The number of minor (soft) faults the thread has made which have not required loading a memory page from disk.
    default String
    The name of the thread.
    int
    The owning process of this thread.
    int
    Priority of the thread, the meaning of which is dependent on the OS.
    default long
    The memory address above which this thread can run.
    long
    The start time of the thread.
    Gets the execution state of the task/thread.
    double
    Gets CPU usage of this thread since a previous snapshot of the same thread, provided as a parameter.
    double
    Gets cumulative CPU usage of this thread.
    int
    The thread id.
    long
    Elapsed/up-time of the thread.
    long
    User time used by the thread.
    default boolean
    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

      default 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()
      Gets the execution state of the task/thread.
      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

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

      default 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.

      Not available on AIX.

      Returns:
      sum of both voluntary and involuntary context switches.
    • getMinorFaults

      default 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

      default 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

      default 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.