title: How to get the heap usage of a single thread at runtime within the same application?
body: <p>I would like to measure the heap usage of a specific Thread from within the app that creates it.
  That app is multi-threaded and has other threads that I am not interested in measuring. </p>
  
  <p><strong>Please do not point me at profilers or other external reporting tools</strong>. I am only interested in code I can run at runtime within the same application.</p>
  
  <p>If possible I am looking to something similar to using <code>ThreadMXBean</code> to measure CPU time. If there is such a solution I have not found (and I have been searching for a while).</p>
  
  <p>Also is there a way to know which memory pools a thread is using? I was thinking of using something similar to</p>
  
  <pre><code>HashSet&lt;String&gt; poolNames = getUsedPoolNames(thisThread);
  long heapUsage = 0L;
  for(MemoryPoolMXBean bean: ManagementFactory.getMemoryPoolMXBeans()) {
      if(poolNames .contains(bean.getName()){
         heapUsage += bean.getHeapUsage().getUsage().getUsed();
      }
  }
  </code></pre>
  
  <p>Would something like this work? What would <code>getUsedPoolNames(~)</code> look like?
  How are memory pools and thread linked?</p>