Package oshi.driver.windows.wmi
Class Win32ProcessCached
- java.lang.Object
-
- oshi.driver.windows.wmi.Win32ProcessCached
-
@ThreadSafe public final class Win32ProcessCached extends java.lang.Object
Utility to query WMI classWin32_Process
using cache
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.Integer,Pair<java.lang.Long,java.lang.String>>
commandLineCache
private java.util.concurrent.locks.ReentrantLock
commandLineCacheLock
private static java.util.function.Supplier<Win32ProcessCached>
INSTANCE
-
Constructor Summary
Constructors Modifier Constructor Description private
Win32ProcessCached()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static Win32ProcessCached
createInstance()
java.lang.String
getCommandLine(int processId, long startTime)
Gets the process command line, while also querying and caching command lines for all running processes if the specified process is not in the cache.static Win32ProcessCached
getInstance()
Get the singleton instance of this class, instantiating the map which caches command lines.
-
-
-
Field Detail
-
INSTANCE
private static final java.util.function.Supplier<Win32ProcessCached> INSTANCE
-
commandLineCache
private final java.util.Map<java.lang.Integer,Pair<java.lang.Long,java.lang.String>> commandLineCache
-
commandLineCacheLock
private final java.util.concurrent.locks.ReentrantLock commandLineCacheLock
-
-
Method Detail
-
getInstance
public static Win32ProcessCached getInstance()
Get the singleton instance of this class, instantiating the map which caches command lines.- Returns:
- the singleton instance
-
createInstance
private static Win32ProcessCached createInstance()
-
getCommandLine
public java.lang.String getCommandLine(int processId, long startTime)
Gets the process command line, while also querying and caching command lines for all running processes if the specified process is not in the cache.When iterating over a process list, the WMI overhead of querying each single command line can quickly exceed the time it takes to query all command lines. This method permits access to cached queries from a previous call, significantly improving aggregate performance.
- Parameters:
processId
- The process ID for which to return the command line.startTime
- The start time of the process, in milliseconds since the 1970 epoch. If this start time is after the time this process was previously queried, the prior entry will be deemed invalid and the cache refreshed.- Returns:
- The command line of the specified process. If the command line is cached from a previous call and the
start time is prior to the time it was cached, this method will quickly return the cached value.
Otherwise, will refresh the cache with all running processes prior to returning, which may incur some
latency.
May return a command line from the cache even after a process has terminated. Otherwise will return the empty string.
-
-