zim32
zim32

Reputation: 2619

A lot of threads in java process

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

enter image description here

Upvotes: 4

Views: 1885

Answers (4)

Andy Dingfelder
Andy Dingfelder

Reputation: 2150

Also if you fire up jconsole (free java app in the jdk) and connect to a running java program, there is a "thread" tab that will let you look at how many threads are, along with a list of threads you can click on for more info.

Upvotes: 1

Michael Borgwardt
Michael Borgwardt

Reputation: 346300

Java uses threads for a lot of things:

  • The application's main thread, of course
  • Any threads the application starts (e.g. SwingWorker)
  • Swing has a separate Event dispatch thread as well as some other housekeeping threads
  • Timers, some of which may get started implicitly
  • One or more threads for Garbage collection
  • I think there's usually a separate thread prepared to run shutdown hooks
  • Other JVM-internal things

Upvotes: 9

oliholz
oliholz

Reputation: 7507

A Simple Java Swing GUI has following Threads:

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)  

Upvotes: 4

KarlP
KarlP

Reputation: 5181

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

but the threads are probably one or two garbage-collection threads, a few gui background threads like timers, cleanup etc.

Upvotes: 1

Related Questions