title: Alternative to ScheduledThreadPoolExecutor to avoid excessive thread allocation
body: <p>I'm using ScheduledThreadPoolExecutor to schedule a large number of tasks to run evenly over an hour.</p>
  <p>There will be tens of thousands of tasks, and this may grow during surges in demand to hundreds of thousands or millions.</p>
  <p>Normally, with a ThreadPoolExecutor, I can set the corePoolSize to a reasonable figure, such as 10 threads, and then allow the pool to grow as necessary.</p>
  <p>However, the documentation for ScheduledThreadPoolExecutor says that:</p>
  <blockquote>
  <p>because it acts as a fixed-sized pool using corePoolSize threads and
  an unbounded queue, adjustments to maximumPoolSize have no useful
  effect</p>
  </blockquote>
  <p>This means that if I set the corePoolSize to 10, it will be capped at 10 threads. If I set the corePoolSize to 1000, it will instantly allocate 1000 threads, even though it may never reach that many active threads.</p>
  <p>Is there an alternative to ScheduledThreadPoolExecutor that will let me set a high maximum thread count, without allocating all of those threads instantly?</p>
  <p>FYI, the reason for the need for a huge active thread count is that the threads are I/O bound, and not CPU bound.</p>