Class Win32ProcessCached


  • @ThreadSafe
    public final class Win32ProcessCached
    extends java.lang.Object
    Utility to query WMI class Win32_Process using cache
    • 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • 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
    • Constructor Detail

      • Win32ProcessCached

        private Win32ProcessCached()
    • 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
      • 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.