Android获取所有线程

private static final String TAG = "log";

private void loadThread() {
        Map<Thread, StackTraceElement[]> stacks = Thread.getAllStackTraces();
        Set<Thread> set = stacks.keySet();
        for (Thread key : set) {
            StackTraceElement[] stackTraceElements = stacks.get(key);
            Log.d(TAG, "----  thread: " + key.getName() + "  start ----");
            for (StackTraceElement st : stackTraceElements) {
                Log.d(TAG, "StackTraceElement: " + st.toString());
            }
            Log.d(TAG, "----  thread: " + key.getName() + "  end ----");
        }
    }
声明:原创文章,版权所有,转载请注明出处,https://litets.com。