Many threads in java process

Why does a simple Java GUI application create so many threads?

enter image description here

+4
source share
4 answers

Java uses threads for a lot of things:

  • The main thread of the application, of course
  • Any threads launched by the application (e.g. SwingWorker)
  • Swing has a separate event dispatch chain, as well as some other topics for the household.
  • Timers, some of which may begin implicitly
  • One or more garbage collection streams
  • I think that usually there is a separate thread prepared to start stop hooks.
  • Other JVM stuff
+9
source

The simple Java Swing GUI has the following topics:

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) 
+4
source

If you attach a debugger, you can see the names and guess yourself,

but the streams are probably one or two garbage collection streams, several gay background streams such as timers, cleanup, etc.

+1
source

Also, if you run jconsole (a free java application in jdk) and connect to a running java program, there is a tab β€œstream” that allows you to see how many threads are there, as well as a list of threads that you can click for more information.

+1
source

All Articles