Class SystemInfo

java.lang.Object
oshi.SystemInfo
All Implemented Interfaces:
SystemInfoProvider

@PublicApi public class SystemInfo extends Object implements SystemInfoProvider
System information. This is the main entry point to OSHI, using JNA for native access.

This object provides getters which instantiate the appropriate platform-specific implementations of OperatingSystem (software) and HardwareAbstractionLayer (hardware).

Quick start:

SystemInfoProvider si = SystemInfoFactory.create();
HardwareAbstractionLayer hal = si.getHardware();
OperatingSystem os = si.getOperatingSystem();

// CPU usage (blocks for 1 second)
double cpuLoad = hal.getProcessor().getSystemCpuLoad(1000L);

// Memory
GlobalMemory mem = hal.getMemory();
long availableBytes = mem.getAvailable();
Platform-specific Hardware and Software objects are retrieved via memoized suppliers and cached on the SystemInfo instance. To conserve memory at the cost of additional processing time, create a new SystemInfo for subsequent calls. To conserve processing time at the cost of additional memory usage, re-use the same instance.

This implementation uses JNA for native access and supports all OSHI platforms (Windows, macOS, Linux, Android, DragonFly BSD, FreeBSD, NetBSD, OpenBSD, Solaris, AIX). Android is routed through the Linux implementations. For JDK 25+, the oshi-core-ffm module provides an alternative entry point (oshi.ffm.SystemInfo) that uses the Foreign Function and Memory (FFM) API for potentially better performance on supported platforms (currently Windows, macOS, Linux, FreeBSD, OpenBSD, and Solaris (illumos)).

Both this class and the FFM entry point require native access. Starting with JEP 472 (JDK 24), the JVM warns when native code is loaded, and a future JDK release will require --enable-native-access. Applications that cannot enable native access can depend on the oshi-common module alone and implement the OSHI interfaces without native calls. See the oshi package documentation for details.

  • Constructor Details

    • SystemInfo

      public SystemInfo()
      Create a new instance of SystemInfo. This is the main entry point to OSHI and provides access to cross-platform code.

      Platform-specific Hardware and Software objects are retrieved via memoized suppliers. To conserve memory at the cost of additional processing time, create a new version of SystemInfo() for subsequent calls. To conserve processing time at the cost of additional memory usage, re-use the same SystemInfo object for future queries.

  • Method Details

    • getPriority

      public int getPriority()
      Description copied from interface: SystemInfoProvider
      Returns the priority of this provider. Higher values indicate higher priority. When multiple providers are available, the one with the highest priority is selected.

      Priority 0 is reserved for a potential future no-native-access fallback. The JNA-based provider (oshi-core) returns 10. The FFM-based provider (oshi-core-ffm) returns 20 (preferred when available).

      Specified by:
      getPriority in interface SystemInfoProvider
      Returns:
      the priority of this provider
    • isAvailable

      public boolean isAvailable()
      Description copied from interface: SystemInfoProvider
      Returns whether this provider is available in the current runtime environment.

      A provider may be unavailable if the current platform is not supported or if required runtime features (such as the FFM API on JDK 25+) are not present.

      Specified by:
      isAvailable in interface SystemInfoProvider
      Returns:
      true if this provider can be used in the current environment
    • getOperatingSystem

      public OperatingSystem getOperatingSystem()
      Creates a new instance of the appropriate platform-specific OperatingSystem.
      Specified by:
      getOperatingSystem in interface SystemInfoProvider
      Returns:
      A new instance of OperatingSystem.
    • getHardware

      public HardwareAbstractionLayer getHardware()
      Creates a new instance of the appropriate platform-specific HardwareAbstractionLayer.
      Specified by:
      getHardware in interface SystemInfoProvider
      Returns:
      A new instance of HardwareAbstractionLayer.