Class SystemInfo
- Direct Known Subclasses:
SystemInfoFFM
This object provides getters which instantiate the appropriate platform-specific FFM implementations of
OperatingSystem (software) and HardwareAbstractionLayer (hardware).
Quick start:
SystemInfo si = new SystemInfo(); // oshi.ffm.SystemInfo
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 requires JDK 25+ and currently supports Windows, macOS, and Linux. It uses the FFM API in place
of JNA for native access, which may offer better performance. For broader platform support (including FreeBSD,
OpenBSD, Solaris, and AIX), use the JNA-based entry point (oshi.SystemInfo) in the oshi-core module.
Both this class and the JNA 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 in oshi-core for details.
All other imports (oshi.hardware.*, oshi.software.os.*) remain the same regardless of which entry
point is used. The API is identical; only the underlying native access mechanism differs.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionoshi.hardware.HardwareAbstractionLayerCreates a new instance of the appropriate platform-specificHardwareAbstractionLayer.oshi.software.os.OperatingSystemCreates a new instance of the appropriate platform-specificOperatingSystem.
-
Constructor Details
-
SystemInfo
public SystemInfo()Create a new instance ofSystemInfo.
-
-
Method Details
-
getOperatingSystem
public oshi.software.os.OperatingSystem getOperatingSystem()Creates a new instance of the appropriate platform-specificOperatingSystem.- Returns:
- A new platform-specific instance implementing
OperatingSystem.
-
getHardware
public oshi.hardware.HardwareAbstractionLayer getHardware()Creates a new instance of the appropriate platform-specificHardwareAbstractionLayer.- Returns:
- A new platform-specific instance implementing
HardwareAbstractionLayer.
-