Code example for ThreadFactoryBuilder

    // create scheduler executor service that services the cleaner tasks 
    // use 2 threads to accommodate the on-demand tasks and reduce the chance of 
    // back-to-back runs 
    ThreadFactory tf =
        new ThreadFactoryBuilder().setNameFormat("Shared cache cleaner").build();
    scheduledExecutor = Executors.newScheduledThreadPool(2, tf);
  protected void serviceStart() throws Exception {
    if (!writeGlobalCleanerPidFile()) { 
      throw new YarnException("The global cleaner pid file already exists! " + 
          "It appears there is another CleanerService running in the cluster"); 
    this.metrics = CleanerMetrics.initSingleton(conf);
    // Start dependent services (i.e. AppChecker) 
Contextual code suggestions in your IDE  Get Codota for Java