Skip to content

Instantly share code, notes, and snippets.

@VladSumtsov
Last active March 30, 2017 14:08
Show Gist options
  • Save VladSumtsov/2cddfdbe3eee282e323c0d92d92b3cca to your computer and use it in GitHub Desktop.
Save VladSumtsov/2cddfdbe3eee282e323c0d92d92b3cca to your computer and use it in GitHub Desktop.
Android, rx threads logger. Helps to debug threads problem.
public void printThreadCountByName(String name) {
Set<Thread> threadSet = getAllStackTraces().keySet();
Observable.from(threadSet)
.filter(thread -> thread.getName().toLowerCase().contains(name.toLowerCase()))
.groupBy(Thread::isAlive)
.flatMap(t -> t)
.groupBy(Thread::getState)
.flatMap(Observable::toList)
.subscribe(list -> {
if (list.isEmpty()) {
System.out.println("CheckThreads " + name + " count 0");
} else {
Thread.State s = list.get(0).getState();
boolean alive = list.get(0).isAlive();
System.out.println("CheckThreads " + name + " || size = " + list.size() + " || state " + s + " || alive = " + alive);
}
}, Throwable::printStackTrace, () -> System.out.println("CheckThreads =================================================="));
}
public void logAllThreads() {
Observable.from(getAllStackTraces().keySet())
.map(thread -> thread.getName() + " || " + thread.getState() + " || alive = " + thread.isAlive()
+ " || itterupted" + thread.isInterrupted() + "\n")
.toList().subscribe(System.out::println);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment