title: Reactor Schedulers keep running long after main thread is done?How to deal with this?
body: <p>I have a question on how to clean up the Scheduler worker threads while using Reactor 3</p>
  
  <pre><code>Flux.range(1, 10000)
  .publishOn(Schedulers.newElastic("Y"))
  .doOnComplete(() -&gt; { 
      // WHAT should one do to ensure the worker threads are cleaned up
      logger.info("Shut down all Scheduler worker threads");
  })
  .subscribe(x -&gt; logger.debug(x+ "**"));
  </code></pre>
  
  <p>What I see when I execute the above code is that once the main thread has finished running the worker thread(s) is/are still in WAITING state for some time.</p>
  
  <pre><code>sun.misc.Unsafe.park(Native Method)
  java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
  java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
  java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1081)
  java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
  java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067)
  java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
  java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
  java.lang.Thread.run(Thread.java:748)
  </code></pre>
  
  <p>Is there a way to control this ?i.e can they be disposed <code>onComplete()</code> ?I tried <code>Schedulers.shutdownNow()</code> and it doesn't help.</p>
  
  <p>On the other hand when I do this I'm able to control the Scheduler disposal.
  Which is the preferred/advocated way ?</p>
  
  <pre><code>reactor.core.scheduler.Scheduler s = Schedulers.newElastic("X");
          Flux.range(1, 10000)
          .concatWith(Flux.empty())
          .publishOn(s)
          .doOnComplete(() -&gt; {           
              s.dispose();
              logger.info("Shut down all Scheduler worker threads");
          })
          .subscribe(x -&gt; logger.debug(x+ "**"));
  </code></pre>