Class SystemInfo
- All Implemented Interfaces:
SystemInfoProvider
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreates a new instance of the appropriate platform-specificHardwareAbstractionLayer.Creates a new instance of the appropriate platform-specificOperatingSystem.intReturns the priority of this provider.booleanReturns whether this provider is available in the current runtime environment.
-
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
-
getPriority
public int getPriority()Description copied from interface:SystemInfoProviderReturns 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:
getPriorityin interfaceSystemInfoProvider- Returns:
- the priority of this provider
-
isAvailable
public boolean isAvailable()Description copied from interface:SystemInfoProviderReturns 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:
isAvailablein interfaceSystemInfoProvider- Returns:
trueif this provider can be used in the current environment
-
getOperatingSystem
Creates a new instance of the appropriate platform-specificOperatingSystem.- Specified by:
getOperatingSystemin interfaceSystemInfoProvider- Returns:
- A new instance of
OperatingSystem.
-
getHardware
Creates a new instance of the appropriate platform-specificHardwareAbstractionLayer.- Specified by:
getHardwarein interfaceSystemInfoProvider- Returns:
- A new instance of
HardwareAbstractionLayer.
-