code: public static ThreadFactory newThreadFactory(final String format, final boolean daemon) {
          final String nameFormat;
          if (!format.contains("%d")) {
              nameFormat = format + "-%d";
          } else {
              nameFormat = format;
          }
  
          return new ThreadFactoryBuilder() //
                  .setNameFormat(nameFormat) //
                  .setDaemon(daemon) //
                  .build();
      }
docs: Returns a new thread factory that uses the given pattern to set the thread name.
  
  @param format
  thread name pattern, where %d can be used to specify the thread number.
  @param daemon
  true for daemon threads
  @return thread factory that uses the given pattern to set the thread name