MCPcopy Create free account
hub / github.com/antlr/codebuff / threadRenaming

Method threadRenaming

output/java_guava/1.4.19/Callables.java:83–102  ·  view source on GitHub ↗

Wraps the given callable such that for the duration of Callable#call the thread that is running will have the given name. @param callable The callable to wrap @param nameSupplier The supplier of thread names, Supplier#get get will be called once for each invocation of the wrapp

(final Callable<T> callable, final Supplier<String> nameSupplier)

Source from the content-addressed store, hash-verified

81 */
82
83 @GwtIncompatible // threads
84 static <T> Callable<T> threadRenaming(final Callable<T> callable, final Supplier<String> nameSupplier) {
85 checkNotNull(nameSupplier);
86 checkNotNull(callable);
87 return new Callable<T>() {
88 @Override
89 public T call() throws Exception {
90 Thread currentThread = Thread.currentThread();
91 String oldName = currentThread.getName();
92 boolean restoreName = trySetName(nameSupplier.get(), currentThread);
93 try {
94 return callable.call();
95 } finally {
96 if (restoreName) {
97 boolean unused = trySetName(oldName, currentThread);
98 }
99 }
100 }
101 };
102 }
103
104 /**
105 * Wraps the given runnable such that for the duration of {@link Runnable#run} the thread that is

Callers 2

executeMethod · 0.95
wrapTaskMethod · 0.95

Calls 1

checkNotNullMethod · 0.45

Tested by

no test coverage detected