Skip to content

Commit e2c046f

Browse files
abheydhyahoisie
authored andcommitted
Added custom ThreadFactory to name threads in LocalUIController
This change introduces a custom ThreadFactory to assign meaningful names to the threads created by the ExecutorService in the LocalUIController. This improves debuggability by making it easier to identify Robolectric-specific threads in thread dumps and profiling tools.
1 parent 7f3165a commit e2c046f

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

robolectric/src/main/java/org/robolectric/android/internal/LocalUiController.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
import java.util.Set;
3333
import java.util.concurrent.ExecutorService;
3434
import java.util.concurrent.Executors;
35+
import java.util.concurrent.ThreadFactory;
3536
import java.util.concurrent.TimeUnit;
37+
import java.util.concurrent.atomic.AtomicInteger;
3638
import org.robolectric.annotation.LooperMode;
3739
import org.robolectric.shadow.api.Shadow;
3840
import org.robolectric.shadows.ShadowLooper;
@@ -46,7 +48,16 @@ public class LocalUiController implements UiController {
4648

4749
private static long idlingResourceErrorTimeoutMs = SECONDS.toMillis(26);
4850
private final HashSet<IdlingResourceProxyImpl> syncedIdlingResources = new HashSet<>();
49-
private final ExecutorService looperIdlingExecutor = Executors.newCachedThreadPool();
51+
private final ExecutorService looperIdlingExecutor =
52+
Executors.newCachedThreadPool(
53+
new ThreadFactory() {
54+
private final AtomicInteger count = new AtomicInteger(1);
55+
56+
@Override
57+
public Thread newThread(Runnable r) {
58+
return new Thread(r, "LocalUiController-" + count.getAndIncrement());
59+
}
60+
});
5061

5162
/**
5263
* Sets the error timeout for idling resources.

0 commit comments

Comments
 (0)