title: Improve ExecutorService to execute process on more then 1 cpu
body: <p>When I run the code below, it seems like only one core is uses by javaw.exe.</p>
  
  <pre><code>int cores = Runtime.getRuntime().availableProcessors();
  System.out.println("Number of cores: " + cores); //8 cores
  
  int partitionSize = alphabet.length / cores;
  ExecutorService service = Executors.newFixedThreadPool(cores);
  List&lt;Future&gt; futures = new ArrayList&lt;Future&gt;();
  
  for (int c = 0; c &lt; cores; c++) {
  
      char[] part = Arrays.copyOfRange(alphabet, c * partitionSize, (c + 1) * partitionSize);
      futures.add(service.submit(new BruteWorker(part) ));
  
  }
  
  for(Future f : futures)
      f.get();
  </code></pre>
  
  <p>According to this image from ProcessExplorer, am I right to think that my app only use 1 CPU ? If yes, how can I do to use all my 8 cores? The total CPU utilization is 12.5 which correspond with 100% / 8cores</p>
  
  <p><a href="https://i.stack.imgur.com/esd35.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/esd35.png" alt="processexplorer"></a></p>
  
  <p>Here is what I get from some println :</p>
  
  <pre><code>Number of cores: 8
  New thread (id = 11)
  New thread (id = 12)
  New thread (id = 13)
  New thread (id = 14)
  New thread (id = 16)
  New thread (id = 15)
  New thread (id = 17)
  New thread (id = 18)
  10000000 tries on thread id = 12
  20000000 tries on thread id = 12
  30000000 tries on thread id = 12
  40000000 tries on thread id = 12
  50000000 tries on thread id = 12
  60000000 tries on thread id = 12
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/yQtOd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yQtOd.png" alt="enter image description here"></a></p>
  
  <p>Why other threads are doing nothing ?</p>
  
  <p>BruteWorker class :</p>
  
  <pre><code>public class BruteWorker implements Runnable {
      private static final char[] alphabet = "eaistnrulodmpcvqgbfjhzxykw0123456789!@#$%&amp;*".toCharArray();
      private static final int maxLength = 8;
      private static Map&lt;String, String&gt; hashes;
      private static MessageDigest md ;
      private char[] partition;
      private long nbTries = 0;
  
      BruteWorker(char[] partition, Map&lt;String, String&gt; hashes) {
          this.partition = partition;
          this.hashes = hashes;
      }
  
      public void run() {
          System.out.println("New thread (id = "+ Thread.currentThread().getId() +")");
          try {
              md = MessageDigest.getInstance("MD5");
              for(char c : this.partition){
                  stringPossibilities(String.valueOf(c), maxLength);
              }
          } catch (NoSuchAlgorithmException e) {
              e.printStackTrace();
          }
          System.out.println("End of thread (id = "+ Thread.currentThread().getId() +")");
      }
  
      //Recursive class
      private void stringPossibilities(String prefix, int length) {
          nbTries++;
          if((nbTries % 10000000) == 0){
              System.out.println(nbTries + " tries on thread id = "+ Thread.currentThread().getId());
          }
          md.update(prefix.getBytes());
          byte[] bytes = md.digest();
          String md5 = getMd5Hash(prefix);
  
          if (hashes.containsKey(md5)){
              System.out.println(prefix + " = " + md5);
          }
  
  
          if (prefix.length() &lt; length){
              for (int i = 0; i &lt; alphabet.length; i++){
                  char c = alphabet[i];
                  stringPossibilities(prefix + c, length);
              }
          }
      }
  
      private String getMd5Hash(String prefix){
          md.update(prefix.getBytes());
          byte[] bytes = md.digest();
          StringBuilder md5 = new StringBuilder();
          for(int j =0; j &lt; bytes.length; j++){
              md5.append(Integer.toString((bytes[j] &amp; 0xff) + 0x100, 16).substring(1));
          }
          return md5.toString();
      }
  
  }
  </code></pre>