为什么简单的Java GUI应用程序会创建如此多的线程?
答案 0 :(得分:9)
Java在很多方面使用线程:
答案 1 :(得分:4)
简单Java Swing GUI具有以下线程:
Thread [AWT-Shutdown] (Suspended)
Object.wait(long) line: not available [native method] [local variables unavailable]
Object.wait() line: 485
AWTAutoShutdown.run() line: 265
Thread.run() line: 619
Daemon Thread [AWT-Windows] (Suspended)
WToolkit.eventLoop() line: not available [native method] [local variables unavailable]
WToolkit.run() line: 295
Thread.run() line: 619
Thread [AWT-EventQueue-0] (Suspended)
Object.wait(long) line: not available [native method] [local variables unavailable]
EventQueue(Object).wait() line: 485
EventQueue.getNextEvent() line: 479
EventDispatchThread.pumpOneEventForFilters(int) line: 236
EventDispatchThread.pumpEventsForFilter(int, Conditional, EventFilter) line: 184
EventDispatchThread.pumpEventsForHierarchy(int, Conditional, Component) line: 174
EventDispatchThread.pumpEvents(int, Conditional) line: 169
EventDispatchThread.pumpEvents(Conditional) line: 161
EventDispatchThread.run() line: 122
Thread [DestroyJavaVM] (Suspended)
答案 2 :(得分:1)
如果您附加调试器,您可以看到名称并猜测自己,
但是线程可能是一个或两个垃圾收集线程, 一些gui背景线程,如定时器,清理等。
答案 3 :(得分:1)
此外,如果您启动jconsole(jdk中的免费java应用程序)并连接到正在运行的java程序,还有一个“线程”选项卡,可以让您查看有多少线程,以及一个线程列表可以点击获取更多信息。