Package com.cedarsoftware.util
Class SystemUtilities
java.lang.Object
com.cedarsoftware.util.SystemUtilities
Utility class providing common system-level operations and information gathering capabilities.
This class offers static methods for accessing and managing system resources, environment
settings, and runtime information.
Key Features:
- System environment and property access
- Memory usage monitoring and management
- Network interface information retrieval
- Process management and identification
- Runtime environment analysis
- Temporary file management
Usage Examples:
// Get system environment variable with fallback to system property
String configPath = SystemUtilities.getExternalVariable("CONFIG_PATH");
// Check available system resources
int processors = SystemUtilities.getAvailableProcessors();
MemoryInfo memory = SystemUtilities.getMemoryInfo();
// Get network configuration
List<NetworkInfo> networks = SystemUtilities.getNetworkInterfaces();
All methods in this class are thread-safe unless otherwise noted. The class cannot be instantiated and provides only static utility methods.
- Author:
- John DeRegnaucourt ([email protected])
Copyright (c) Cedar Software LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
License
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static class
static class
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addShutdownHook
(Runnable hook) Add shutdown hook with safe executionstatic File
createTempDirectory
(String prefix) Create temporary directory that will be deleted on JVM exitstatic int
Get available processors, considering Docker container limitsstatic long
Get process ID of current JVMgetEnvironmentVariables
(Predicate<String> filter) Get all environment variables with optional filteringstatic String
Fetch value from environment variable and if not set, then fetch from System properties.static SystemUtilities.MemoryInfo
Get current JVM memory usage informationstatic List
<SystemUtilities.NetworkInfo> Get network interface informationstatic double
Get system load average over last minutestatic TimeZone
Get system timezone, considering various sourcesstatic boolean
hasAvailableMemory
(long requiredBytes) Check if enough memory is availablestatic boolean
isJavaVersionAtLeast
(int major, int minor) Check if running on specific Java version or higher
-
Field Details
-
OS_NAME
-
JAVA_VERSION
-
USER_HOME
-
TEMP_DIR
-
-
Method Details
-
getExternalVariable
Fetch value from environment variable and if not set, then fetch from System properties. If neither available, return null.- Parameters:
var
- String key of variable to return
-
getAvailableProcessors
public static int getAvailableProcessors()Get available processors, considering Docker container limits -
getMemoryInfo
Get current JVM memory usage information -
getSystemLoadAverage
public static double getSystemLoadAverage()Get system load average over last minute- Returns:
- load average or -1.0 if not available
-
isJavaVersionAtLeast
public static boolean isJavaVersionAtLeast(int major, int minor) Check if running on specific Java version or higher -
getCurrentProcessId
public static long getCurrentProcessId()Get process ID of current JVM- Returns:
- process ID for the current Java process
-
createTempDirectory
Create temporary directory that will be deleted on JVM exit- Throws:
IOException
-
getSystemTimeZone
Get system timezone, considering various sources -
hasAvailableMemory
public static boolean hasAvailableMemory(long requiredBytes) Check if enough memory is available -
getEnvironmentVariables
Get all environment variables with optional filtering -
getNetworkInterfaces
Get network interface information- Throws:
SocketException
-
addShutdownHook
Add shutdown hook with safe execution
-