Last active
March 30, 2017 14:08
-
-
Save VladSumtsov/2cddfdbe3eee282e323c0d92d92b3cca to your computer and use it in GitHub Desktop.
Android, rx threads logger. Helps to debug threads problem.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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