title: Adding a Pool of Threads in a RxJava Flow
body: <p>I was wondering if I can use the <strong>RxJava</strong> library in order to add some concurrency in the following use-case:</p>
  
  <ul>
  <li>Fetch sequentially a <code>String</code> column from an existing <code>ResultSet</code> with a custom <code>Observable</code> (something like <code>ResultSetObservable.create(resultSet)</code>)</li>
  <li>Invoking a Web Service for each of these value (with a <code>InvokeWebServiceFunc1&lt;String, Pair&lt;String, Integer&gt;&gt;()</code> instance, for example) in order to retrieve some statistiques related to the <code>String</code> (note that the <code>String</code> in the <code>Pair</code> is the same as the one passed in input)</li>
  <li>Print everything in a CSV format (with a <code>ExportAsCSVAction1&lt;Pair&lt;String, Integer&gt;&gt;(PrintStream printStream)</code>). </li>
  </ul>
  
  <p>So here is what I have:</p>
  
  <pre><code>ResultSetObservable.create(resultSet)
      .map(new InvokeWebServiceFunc1&lt;String, Pair&lt;String, Integer&gt;&gt;())
      .subscribe(new ExportAsCSVAction1&lt;Pair&lt;String, Integer&gt;&gt;(System.out));
  </code></pre>
  
  <p>It works well but as the Web Service may take some time for some of the <code>String</code> input, I want to add some concurrency by <strong>having a thread pool like behavior for the mapping</strong> (of 10 threads for example) but I <em>need</em> the <code>ExportAsCSVAction0</code> to <strong>be called in the same thread</strong> (and actually the current thread would be perfect). </p>
  
  <p>Can you please help me? I can't figure if using the <code>toBlocking().forEach()</code> pattern is the right solution here and I do not understand where to use the <code>Schedulers.from(fixedThreadPool)</code> (in the <code>observeOn()</code> or in the <code>subscribeOn()</code>).</p>
  
  <p>Thank you for any help!</p>