title: How to access running threads inside ThreadPoolExecutor?
body: <p>I have a queue of running threads and would like to expose some of its data while it is executed, to monitor the process.</p>
  
  <p><code>ThreadPoolExecutor</code> provides access to its queue and I can iterate through these objects to call my overridden <code>toString()</code> method, but these are only threads that are waiting for execution.</p>
  
  <p>Is there a way to access threads that are currently running to call my method? Or maybe there's a better approach for this task in general?</p>
  
  <p>To clarify a bit more about the purpose, here's some code of general idea:</p>
  
  <pre><code>public class GetDataTask implements Runnable {
      private String pageNumber;
      private int dataBlocksParsed;
      private String source;
      private String dataType;
  
  
      public GetDataTask(String source, String dataType) {
          this.source = source;
          this.dataType = dataType;
      }
  
      @Override
      public void run() {
          //do stuff that affects pageNumber and dataBlocksParsed
      }
  
      @Override
      public String toString() {
          return "GetDataTask{" +
              "source=" + source +
              ", dataType=" + dataType +
              ", pageNumber=" + pageNumber +
              ", dataBlocksParsed=" + dataBlocksParsed +
              '}';
      }
  }
  </code></pre>
  
  <p>and a class holding the executor:</p>
  
  <pre><code>public class DataParseManager {
      private static ThreadPoolExecutor executor = new ThreadPoolExecutor(100, 100, 20, TimeUnit.SECONDS, new ArrayBlockingQueue&lt;&gt;(300));
  
      public void addParseDataTask(String source, String dataType) {
          executor.execute(new GetDataTask(source, dataType));
      }
  
      // here's the method that I need
      public String getInfo() {
          StringBuilder info = new StringBuilder();
          //and here's the method that I'm missing - executor.getActiveThreads()
          for (Runnable r : executor.getActiveThreads()) {
              info.append(((GetDataTask) r).toString()).append('\n');
          }
          return info.append(executor.toString()).toString();
     }
  }
  </code></pre>