Every Java application starts with a main method that runs in the main
thread. In a Swing program,the main thread is short-lived. It
schedules the construction of the user interface in the event dispatch
thread and then exits…Other threads,such as the thread that posts
events into the event queue,are running behind the scenes,but those
threads are invisible to the application programmer.
它让我觉得JVM使用一组标准线程来容纳每个Java程序.我认为它们包括:
>主线程
>事件派发线程
我想这些线程就像JVM授予每个Java应用程序的堆空间,堆栈等其他资源一样.客户应该在不同的线程中正确地完成不同的工作.比如只在事件派发线程中做与Swing相关的事情.
我对此是否正确?我在哪里可以找到一些权威参考? JVM规范似乎没有这个.
如果我从不使用事件调度线程,例如在控制台应用程序中,我可以禁用它来节省一些cpu周期吗?
加1
下面的链接解释了有关Swing框架如何使用线程的详细信息.
Swing中的并发性
http://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html
解决方法
VM thread
This thread waits for operations to appear that require the JVM to reach a safe-point. The reason these operations have to happen on a separate thread is because they all require the JVM to be at a safe point where modifications to the heap can not occur. The type of operations performed by this thread are “stop-the-world” garbage collections,thread stack dumps,thread suspension and biased locking revocation.
Periodic task thread
This thread is responsible for timer events (i.e. interrupts) that are used to schedule execution of periodic operations
GC threads
These threads support the different types of garbage collection activities that occur in the JVM
Compiler threads
These threads compile byte code to native code at runtime
Signal dispatcher thread
This thread receives signals sent to the JVM process and handle them inside the JVM by calling the appropriate JVM methods.
编辑以回应赏金(你是对的,有些人的博客是非常不稳定的支持,虽然这是我能找到的所有内容总结的最佳位置)— OpenJDK对他们runtime system的描述(打算成为HotSpot的副本)描述同一件事情:
People are often surprised to discover that even executing a simple “Hello World” program can result in the creation of a dozen or more threads in the system. These arise from a combination of internal VM threads,and library related threads (such as reference handler and finalizer threads). The main kinds of VM threads are as follows:
VM thread: This singleton instance of VMThread is responsible for executing VM operations…
Periodic task thread: This singleton instance of WatcherThread simulates timer interrupts for executing periodic operations within the VM
GC threads: These threads,of different types,support parallel and concurrent garbage collection
Compiler threads: These threads perform runtime compilation of bytecode to native code
Signal dispatcher thread: This thread waits for process directed signals and dispatches them to a Java level signal handling method
我找不到Oracle的任何引用来确认它们的实现是一样的,但是来自Sun的Paul Hohenesee的演讲中的these slides提到:
Thread types
Java,aka mutator
One VM thread: GC,deoptimization,etc.
Compiler
Watcher,timer
Low memory monitor
Garbage collector,parallel collectors
鉴于此演示文稿必须至少6年,实现可能略有改变,但组件或多或少相同.