2
我正在嘗試獲取應用程序中的所有活動/正在運行的線程。我寫了下面的發佈代碼,並且得到了下面的發佈結果。 事實上,沒有在貼輸出線程屬於我的應用程序,除了如何在我的應用程序中獲取正在運行的線程
07-10 15:36:48.621 19333-19624/eu.men.m2sapp D/GcmIntentService: thread.toString():Thread[IntentService[GcmIntentService],5,main]
1)是什麼數字5表示?
2)似乎'getAllStackTraces'檢索系統範圍內的所有活動線程,但是如何獲取僅在我的應用程序中運行的線程?
代碼:
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]
plus1。你能告訴我如何獲得從我的代碼開始的線程嗎? – user2121
@ user2121:在啓動它們時跟蹤它們。從我所看到的,框架開始了你的所有線程,除非你決定創建自己的名爲'IntentService'的類。 – CommonsWare
你能告訴我你是怎麼知道我從IntentService開始我的線程的嗎?好的,我們事先知道IntentService是Android類,但除了IntentService之外,應該知道一個線程是否從特定類開始?也許是因爲在課程名稱後面有'[]'方括號? – user2121