title: How to determine the max possible fixed thread pool size?
body: <p>Is there a method or utility to determine how many threads can be created in a program, for example with <code>Executors.newFixedThreadPool(numberThreads)</code>? The following custom rollout works but is obviously not an enterprise grade solution:</p>
  
  <pre><code>public class ThreadCounter {
      public static void main(String[] args) {
          System.out.println("max number threads = " + getMaxNumberThreads());
      }
  
      static int getMaxNumberThreads() {
          final int[] maxNumberThreads = {0};
          try {
              while (true) {
                  new Thread(() -&gt; {
                      try {
                          maxNumberThreads[0]++;
                          Thread.sleep(Integer.MAX_VALUE);
                      } catch (InterruptedException e) {
                      }
                  }).start();
              }
          } catch (Throwable t) {
          }
          return maxNumberThreads[0];
      }
  }
  </code></pre>