title: Is it possible and how to have Scala par consume threads from a thread pool?
body: <p>In Scala 2.11.8 I'm using <code>par</code> to parallelize a large and lengthy <code>foreach</code>. I'm also trying to optimize the code to avoid creating new instances of an object each time and therefore I need to use <code>DynamicVariable</code>. However, I noticed that still there are many instances of this class created which leads me to think that <code>par</code> is always spanning new threads rather than reusing them. Thus the OP how to have par consume threads from a pool of limited reusable threads? is this possible?</p>
  
  <pre><code>for (k &lt;- 0 until 5) {
      // avoid creating instances of PearsonsIncCorr
      val inc = new DynamicVariable[PearsonsIncCorr](new PearsonsIncCorr)
      elems.par foreach { pair =&gt; // &lt;======= Here I'd like par to consume from a Thread pool 
        inc.withValue(new PearsonsIncCorr) {
          inc.reset(...)
          // compute incremental correlation
        }
      }
  }
  </code></pre>