This is specific to Windows, and it has to do with the way the list of performance monitor process object \Process(java#0) instances resets when other instances exits.
When I start java.exe, and there is already another java.exe process running, the list of Processes will look like:
\Process(java#0) <<-- already running instance
\Process(java#1) <<-- my instance
Our code sets up a Pdh query against \Process(java#1) and all is well ...for a time.
Then say the first java.exe(#0) process exits.
This list is now reset so that the second java.exe instance (previous #1), now has the identifier (java#0).
The problem is the PDH queries are registered for java#1, which means they are invalidated when this happens. The permutations of this really bad Win32 api could be even worse if there was another java#2 process running as welll:
As the list "shifts", the first java#1 could still continue to use its registered query, however, now it will pull in performance data from the previous java#2 process, not its own data.
Unbelievable that there is no way to specify the PID when register process specific counters - I will add a safety guard which add queries for all instances running, and do a check on every query what the current PID is mapped to which name (java#1, java#2 etc) to identify query of the correct process instance.
Thanks for reporting this.