gpt4 book ai didi

java - 如何仅在我的应用程序中获取正在运行的线程

转载 作者:搜寻专家 更新时间:2023-11-01 08:26:01 25 4
gpt4 key购买 nike

我正在尝试获取应用程序中所有 Activity/正在运行的线程。我写了下面发布的代码,我得到了下面发布的结果。实际上,发布的输出中的线程都不属于我的应用程序,除了

07-10 15:36:48.621 19333-19624/eu.men.m2sapp D/GcmIntentService: thread.toString():Thread[IntentService[GcmIntentService],5,main]

1) 数字 5 表示什么?

2)“getAllStackTraces”似乎检索了系统范围内的所有 Activity 线程,但我如何才能获取仅在我的应用程序中运行的线程?

代码:

Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
Thread[] threadArray = threadSet.toArray(new Thread[threadSet.size()]);
Thread thread = null;
for (int i = 0; i < threadArray.length; i++) {
thread = threadArray[i];
Log.d(TAG, "thread.toString():" + thread.toString());
}

输出:

07-10 15:36:48.621 19333-19624/eu.men.m2sapp D/GcmIntentService: thread.toString():Thread[IntentService[GcmIntentService],5,main]
07-10 15:36:48.622 19333-19624/eu.men.m2sapp D/GcmIntentService: thread.toString():Thread[FinalizerWatchdogDaemon,5,system]
07-10 15:36:48.622 19333-19624/eu.men.m2sapp D/GcmIntentService: thread.toString():Thread[Timer-0,5,main]
07-10 15:36:48.622 19333-19624/eu.men.m2sapp D/GcmIntentService: thread.toString():Thread[RenderThread,5,main]
07-10 15:36:48.622 19333-19624/eu.men.m2sapp D/GcmIntentService: thread.toString():Thread[ReferenceQueueDaemon,5,system]
07-10 15:36:48.622 19333-19624/eu.men.m2sapp D/GcmIntentService: thread.toString():Thread[FinalizerDaemon,5,system]
07-10 15:36:48.622 19333-19624/eu.men.m2sapp D/GcmIntentService: thread.toString():Thread[Binder_3,5,main]
07-10 15:36:48.622 19333-19624/eu.men.m2sapp D/GcmIntentService: thread.toString():Thread[main,5,main]
07-10 15:36:48.622 19333-19624/eu.men.m2sapp D/GcmIntentService: thread.toString():Thread[Signal Catcher,5,system]
07-10 15:36:48.622 19333-19624/eu.men.m2sapp D/GcmIntentService: thread.toString():Thread[Binder_1,5,main]
07-10 15:36:48.622 19333-19624/eu.men.m2sapp D/GcmIntentService: thread.toString():Thread[Binder_2,5,main]
07-10 15:36:48.622 19333-19624/eu.men.m2sapp D/GcmIntentService: thread.toString():Thread[GCDaemon,5,system]
07-10 15:36:48.622 19333-19624/eu.men.m2sapp D/GcmIntentService: thread.toString():Thread[pool-1-thread-1,5,main]
07-10 15:36:48.622 19333-19624/eu.men.m2sapp D/GcmIntentService: thread.toString():Thread[JDWP,5,system]
07-10 15:36:48.623 19333-19624/eu.men.m2sapp D/GcmIntentService: thread.toString():Thread[HeapTrimmerDaemon,5,system]
07-10 15:36:48.623 19333-19624/eu.men.m2sapp D/GcmIntentService: thread.toString():Thread[Thread-52709,5,main]

最佳答案

Actually, none of the threads in the posted output belong to my App

所有这些线程都属于您的应用进程。大多数来自框架,而不是您的代码。

it seems that 'getAllStackTraces' retrieves all the active threads system-wide

不,它会检索您进程中的线程。

how can I get the threads that are only running in my App?

你已经是了。

what does number 5 indicates?

我认为这是线程优先级。

关于java - 如何仅在我的应用程序中获取正在运行的线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45013856/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com