Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

multithreading - What are these threads which are spwaned when a Java application begins its execution?

I have created a simple Java application which has a JFrame and few JButtons. When I tried to inspect the java application using JVMTI I found that though I did not create any explicit threads there were lot of them spawned.

I could find the following threads:

  • DestroyJavaVM
  • AWT-EventQueue-0
  • AWT-Shutdown
  • AWT-XAWT- Daemon Thread
  • Java2D Disposer- Daemon Thread
  • Thread-0- Daemon Thread [Created by the JVMTI Agent]
  • Signal Dispatcher- Daemon Thread
  • Finalize- Daemon Thread
  • Reference Handler- Daemon Thread

Most of them were in Runnable state. Can someone tell me the function of these threads?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

These threads are used by the underlying libraries to manage the widgets, display, event-loop, and other plumbing that is needed for your graphical application.

A GUI application usually has a lot of moving parts, and if you've noticed you don't have to explicitly write any code to manage these parts (e.g., updating the screen, or drawing a button, or handling a mouse movement). Is is this set of background threads that are responsible for managing these parts, and making it as easy as possible for you to focus on your application logic.

These threads are spawned by the libraries that you use (e.g., AWT, Swing, etc.) and usually clean themselves (and the resources that they manage) up upon termination.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...