title: How to use Executor when there are thousands/dynamic number of tasks?
body: <p>I just found out about Java's Executor and I'm thinking whether it fits my needs. I have a database, to which tasks are constantly added.</p>
  
  <ol>
  <li><p>I SQL SELECT all rows(tasks) from the database. At any time, there could be 100000, 200, 3 or 0 of them.</p></li>
  <li><p>I see all examples are like this:</p>
  
  <pre><code>ExecutorService taskExecutor = Executors.newFixedThreadPool(50);
  while(...) {
      taskExecutor.execute(new MyTask());
  }
  </code></pre>
  
  <p>How could it be adjusted to my scenario? I can't just instantiate 100000 of MyTask's, it will waste a ton of memory.</p></li>
  <li><p>How should I wait for finish and check again? I can't just wait until 100000 tasks are finished, because first one might finish in 5 secs and will stay unused for a long time until last one is finished, so we will be wasting time.</p></li>
  </ol>