title: Pro and Cons of opening multiple InputStream?
body: <p>While coding <a href="https://stackoverflow.com/a/16654313/1654265">the solution</a> to the problem of <a href="https://stackoverflow.com/questions/16585384/best-practices-to-create-and-download-a-huge-zip-from-several-blobs-in-a-webap">downloading a huge dynamic zip with low RAM impact</a>, an idea started besieging me, and led to this question, asked for pure curiosity / hunger of knowledge:</p>
  
  <p>What kind of drawbacks could I meet with if, instead of loading the <code>InputStream</code>s one at a time (with separate queries to the database), I would load all the <code>InputStream</code>s in a single query, returning a List of (<em>n</em>, potentially thousands, "opened") <code>InputStreams</code> ?</p>
  
  <p><strong>Current (safe) version: <em>n</em> queries, <em>one</em> inputStream instantiated at a time</strong></p>
  
  <pre><code>for (long id : ids){
      InputStream in = getMyService().loadStreamById(id);
      IOUtils.copyStream(in, out);
      in.close();
  }
  </code></pre>
  
  <p><strong>Hypothetical version: one query, <em>n</em> instantiated inputStreams</strong></p>
  
  <pre><code>List&lt;InputStream&gt; streams = getMyService().loadAllStreams();
  
  for (InputStream in : streams){     
      IOUtils.copyStream(in, out);
      in.close();
      in = null;
  }
  </code></pre>
  
  <p>Which are the pro and cons of the second approach, excluding the (I suppose little) amount of memory used to keep multiple java InputStream instantiated ?</p>
  
  <p>Could it lead to some kind of network freeze or database stress (or lock, or problems if others read/write the same BLOB field the Stream is pointing to, etc...) more than multiple queries ?</p>
  
  <p>Or are they smart enough to be almost invisible until asked for data, and then <code>1 query + 1000 active stream</code> could be better than <code>1000 query + 1 active stream</code> ?</p>