guava/src/com/google/common/util/concurrent/AbstractScheduledService.java
protected ScheduledExecutorService executor() {
    @WeakOuter
    class ThreadFactoryImpl implements ThreadFactory {
      @Override
      public Thread newThread(Runnable runnable) {
        return MoreExecutors.newThread(serviceName(), runnable);
      }
    }
    final ScheduledExecutorService executor =
        Executors.newSingleThreadScheduledExecutor(new ThreadFactoryImpl());
    // Add a listener to shutdown the executor after the service is stopped. This ensures that the
    // JVM shutdown will not be prevented from exiting after this service has stopped or failed.
    // Technically this listener is added after start() was called so it is a little gross, but it
    // is called within doStart() so we know that the service cannot terminate or fail concurrently
    // with adding this listener so it is impossible to miss an event that we are interested in.
    addListener(
        new Listener() {
          @Override
          public void terminated(State from) {
            executor.shutdown();
          }

          @Override
          public void failed(State from, Throwable failure) {
            executor.shutdown();
          }
        },
        directExecutor());
    return executor;
  }
protected ScheduledExecutorService executor() {
    @WeakOuter
    class ThreadFactoryImpl implements ThreadFactory {
      @Override
      public Thread newThread(Runnable runnable) {
        return MoreExecutors.newThread(serviceName(), runnable);
      }
    }
    final ScheduledExecutorService executor =
        Executors.newSingleThreadScheduledExecutor(new ThreadFactoryImpl());
    // Add a listener to shutdown the executor after the service is stopped. This ensures that the
    // JVM shutdown will not be prevented from exiting after this service has stopped or failed.
    // Technically this listener is added after start() was called so it is a little gross, but it
    // is called within doStart() so we know that the service cannot terminate or fail concurrently
    // with adding this listener so it is impossible to miss an event that we are interested in.
    addListener(
        new Listener() {
          @Override
          public void terminated(State from) {
            executor.shutdown();
          }

          @Override
          public void failed(State from, Throwable failure) {
            executor.shutdown();
          }
        },
        directExecutor());
    return executor;
  }
Returns the {@link ScheduledExecutorService} that will be used to execute the {@link #startUp},
{@link #runOneIteration} and {@link #shutDown} methods. If this method is overridden the
executor will not be {@linkplain ScheduledExecutorService#shutdown shutdown} when this service
{@linkplain Service.State#TERMINATED terminates} or {@linkplain Service.State#TERMINATED
fails}. Subclasses may override this method to supply a custom {@link ScheduledExecutorService}
instance. This method is guaranteed to only be called once.

<p>By default this returns a new {@link ScheduledExecutorService} with a single thread thread
pool that sets the name of the thread to the {@linkplain #serviceName() service name}. Also,
the pool will be {@linkplain ScheduledExecutorService#shutdown() shut down} when the service
{@linkplain Service.State#TERMINATED terminates} or {@linkplain Service.State#TERMINATED
fails}.