@GwtIncompatible // threads
  static Runnable threadRenaming(final Runnable task, final Supplier<String> nameSupplier) {
    checkNotNull(nameSupplier);
    checkNotNull(task);
    return new Runnable() {
      @Override
      public void run() {
        Thread currentThread = Thread.currentThread();
        String oldName = currentThread.getName();
        boolean restoreName = trySetName(nameSupplier.get(), currentThread);
        try {
          task.run();
        } finally {
          if (restoreName) {
            boolean unused = trySetName(oldName, currentThread);
          }
        }
      }
    };
  }
@GwtIncompatible 
  static Runnable threadRenaming(final Runnable task, final Supplier<String> nameSupplier) {
    checkNotNull(nameSupplier);
    checkNotNull(task);
    return new Runnable() {
      @Override
      public void run() {
        Thread currentThread = Thread.currentThread();
        String oldName = currentThread.getName();
        boolean restoreName = trySetName(nameSupplier.get(), currentThread);
        try {
          task.run();
        } finally {
          if (restoreName) {
            boolean unused = trySetName(oldName, currentThread);
          }
        }
      }
    };
  }
@ GwtIncompatible // threads static Runnable threadRenaming ( final Runnable task , final Supplier < String > nameSupplier ) { checkNotNull ( nameSupplier ) ; checkNotNull ( task ) ; return new Runnable ( ) { @ Override public void run ( ) { Thread currentThread = Thread . currentThread ( ) ; String oldName = currentThread . getName ( ) ; boolean restoreName = trySetName ( nameSupplier . get ( ) , currentThread ) ; try { task . run ( ) ; } finally { if ( restoreName ) { boolean unused = trySetName ( oldName , currentThread ) ; } } } } ; }
Wraps the given runnable such that for the duration of {@link Runnable#run} the thread that is
running with have the given name.


@param task The Runnable to wrap
@param nameSupplier The supplier of thread names, {@link Supplier#get get} will be called once
for each invocation of the wrapped callable.
Wraps the given runnable such that for the duration of { @link Runnable#run } the thread that is running with have the given name .