code: private void balance() {
          // only try to balance when we're not terminating
          if(!isTerminated()) {
              Set<Map.Entry<Thread, Tracking>> threads = liveThreads.entrySet();
              long liveAvgTimeTotal = 0;
              long liveAvgCpuTotal = 0;
              long liveCount = 0;
              for (Map.Entry<Thread, Tracking> e : threads) {
                  if (!e.getKey().isAlive()) {
                      // thread is dead or otherwise hosed
                      threads.remove(e);
                  } else {
                      liveAvgTimeTotal += e.getValue().avgTotalTime;
                      liveAvgCpuTotal += e.getValue().avgCpuTime;
                      liveCount++;
                  }
              }
              long waitTime = 1;
              long cpuTime = 1;
              if(liveCount > 0) {
                  waitTime = liveAvgTimeTotal / liveCount;
                  cpuTime = liveAvgCpuTotal / liveCount;
              }
  
              int size = 1;
              if(cpuTime > 0) {
                  size = (int) ceil((CPUS * targetUtilization * (1 + (waitTime / cpuTime))));
              }
              size = Math.min(size, threadPoolExecutor.getMaximumPoolSize());
  
              // TODO remove debugging
              //System.out.println(waitTime / 1000000 + " ms");
              //System.out.println(cpuTime / 1000000 + " ms");
              //System.out.println(size);
  
              threadPoolExecutor.setCorePoolSize(size);
          }
      }
docs: Compute and set the optimal number of threads to use in this pool.