Class SystemInfo
This object provides getters which instantiate the appropriate platform-specific implementations of
OperatingSystem (software) and HardwareAbstractionLayer (hardware).
Quick start:
SystemInfo si = new 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 uses JNA for native access and supports
all OSHI platforms (Windows, macOS, Linux, Android, FreeBSD, OpenBSD, Solaris, AIX). Android is routed through the
Linux implementations. For JDK 25+, the oshi-core-java25 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, and Linux).
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic PlatformEnumDeprecated.oshi.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. 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
SystemInfoobject for future queries.
-
-
Method Details
-
getCurrentPlatform
Deprecated.UsePlatformEnum.getCurrentPlatform()instead.Gets thePlatformEnumvalue representing this system.- Returns:
- Returns the current platform
-
getOperatingSystem
public oshi.software.os.OperatingSystem getOperatingSystem()Creates a new instance of the appropriate platform-specificOperatingSystem.- Returns:
- A new instance of
OperatingSystem.
-
getHardware
public oshi.hardware.HardwareAbstractionLayer getHardware()Creates a new instance of the appropriate platform-specificHardwareAbstractionLayer.- Returns:
- A new instance of
HardwareAbstractionLayer.
-
PlatformEnum.getCurrentPlatform()instead.