title: How to properly use threadpool and get a result from a thread?
body: <p>i'm triyng to experiment the multithread programming (new for me) and i have some questions.</p>
  
  <p>I'm using a <code>ThreadPoolTaskExecutor</code>with a TestTask which implements <code>Runnable</code> and a <code>run</code> method wich sleeps for X seconds. Everyting went smoothly and all my TestTask were executed in a different thread. Ok.
  Now the tricky part is that i want to know the result of an operation made in the thread. So i read some stuff on Google/stack/etc and i tried to use <code>Future</code>. And it's not working well anymore :/</p>
  
  <p>I use the <code>get</code> method to get (oh really ?) the result of the <code>call</code> method and that part is working but the TestTask are executed one after another (and not at the same time like before). So i'm guessing i didn't understand properly something but i don't know what... and that's why i need your help !</p>
  
  <p>The class wich launch test :</p>
  
  <pre><code>public void test(String test) {
  
      int max = 5;
      for (int i = 0; i &lt; max; i++) {
          TestThreadService.launch(i);
      }
      System.out.println("END");
  
  }
  </code></pre>
  
  <p>The TestThreadService class :</p>
  
  <pre><code>public class TestThreadService {
  
  private ThreadPoolTaskExecutor taskExecutor;
  
  public void launch(int i) {
      System.out.println("ThreadNumber : "+i);
      taskExecutor.setWaitForTasksToCompleteOnShutdown(false);
      TestTask testTask = new TestTask(i);
      FutureTask&lt;Integer&gt; futureOne = new FutureTask&lt;Integer&gt;(testTask);
      taskExecutor.submit(futureOne);
      try {
          Integer result = futureOne.get();
          System.out.println("LAUNCH result : "+i+" - "+result);
      } catch (Exception e) {
          e.printStackTrace();
      }
    }
  
  public void setTaskExecutor(ThreadPoolTaskExecutor taskExecutor) {
    this.taskExecutor = taskExecutor;
  }
  
  }
  </code></pre>
  
  <p>And the TestTask Class :</p>
  
  <pre><code>public class TestTask implements Callable&lt;Integer&gt; {
  
  public Integer threadNumber;
  private Integer valeur;
  
    public TestTask(int i) {
      this.threadNumber = i;
    }
  
    public void setThreadNumber(Integer threadNumber) {
      this.threadNumber = threadNumber;
    }
  
      @Override
      public Integer call() throws Exception {
          System.out.println("Thread start " + threadNumber);
          // generate sleeping time
          Random r = new Random();
          valeur = 5000 + r.nextInt(15000 - 5000);
          System.out.println("Thread pause " + threadNumber + " " + valeur);
          try {
              Thread.sleep(valeur);
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
          System.out.println("Thread stop" + threadNumber);
          return this.valeur;
      }
  
  }
  </code></pre>
  
  <p>I'm not bad in Java but this is the first time i'm trying to use different thread so i'ts kind a new for me.</p>
  
  <p>What am i doing wrong ?</p>
  
  <p>Thanks !</p>