private static < T > Callable < T > threadRenaming ( final String name , final Callable < T > callable ) { checkNotNull ( name ) ; checkNotNull ( callable ) ; return new Callable < T > ( ) { @ Override public T call ( ) throws Exception { Thread currentThread = Thread . currentThread ( ) ; String oldName = currentThread . getName ( ) ; currentThread . setName ( name ) ; try { return callable . call ( ) ; } finally { currentThread . setName ( oldName ) ; } } } ; }
Returns a callable that renames the the thread that the given callable runs in .