title: How to maintain a persistent background thread?
body: <p><strong>Summary</strong></p>
  
  <p>I have a server that should be long-running, and that spawns a few background threads for IO.  I'm trying to make sure that the background/IO threads don't go down, or that they'll be brought back up if they do go down.</p>
  
  <p><strong>Current Solution</strong></p>
  
  <p>Currently my main loop just checks the status of all background checks (pseudo-code below).  I think there should be a better way.</p>
  
  <pre><code>while (!Thread.currentThread().isInterrupted()) {
      maintainThreads();
      doWork();
      condition.await(30, TimeUnit.SECONDS);
  }
  </code></pre>
  
  <p><strong>My Attempt</strong></p>
  
  <p>I'm considering switching to a <code>SingleThreadExecutor</code>, with a custom <code>queue</code> that won't remove the <code>Runnable</code> when it pulls the next task.  The <code>executor</code> would then manage the threads for me so I could take it out of my main loop.</p>
  
  <p>I'm worried that having one executor for each thread will be a performance hit, and that there are simpler/better solutions that exist for this problem.  I've also considered setting up shutdown hooks for each thread to have them just restart themselves.</p>
  
  <p>Any help would be appreciated.</p>