title: Iterate through threads run via ThreadPoolTaskExecutor
body: <p>I have a <code>ThreadPoolTaskExecutor</code> and when I create a <code>Process</code> which implements <code>Runnable</code> I run it via: <code>executor.execute(process)</code>.</p>
  
  <p>Now, before calling <code>execute</code> I want to check one field from <code>Process</code> object and compare it with ALL other <strong>currently running</strong> processes, executed by my <code>ThreadPoolTaskExecutor</code>. How I can do that, not generating a concurrent problem?</p>
  
  <p>Code:</p>
  
  <pre><code>public class MyApp {
  
     ThreadPoolTaskExecutor executor;
  
     //...
  
     public void runProcesses {
         Process firstone = new Process(1);
         Process nextOne = new Process(1);
  
  
         // iterate through all processes started via executor and currently running,
         // verify if there is any process.getX() == 1, if not run it
  
         executor.execute(firstone );
  
         //wait till firstone will end becouse have the same value of X
         executor.execute(nextOne); // this cant be perform until the first one will end
     }
  }
  
  public class Process {
      private int x;
  
      //...
  
      public Process (int x){
          this.x = x;
      }
      public int getX(){
           return this.x;
      }
  
  }
  </code></pre>
  
  <p>I was thinking about createing simple <code>Set</code> of process started and add new one to it. But I have problem how to determine is it still running and remove it from set when it is done. So now I'm thinking about iterating through running threads, but completly dunno how.</p>