JVM在启动时分叉了多少个线程?

时间:2012-03-28 22:11:52

标签: java multithreading concurrency parallel-processing real-time

我只是想避免上下文切换,因为它会引入很多延迟。所以,如果我正确地思考,我希望每个处理器最多有一个线程。如果处理器支持虚拟并行(超线程我认为它就是名字!)那么我可以拥有双倍数量的线程。

Ex:4个超线程处理器=最多8个线程

当然操作系统也需要处理器,所以我可能在这里很天真。

无论如何,知道JVM在启动时创建的线程数是一个好的开始。

1 个答案:

答案 0 :(得分:4)

JVM只启动1个用户线程,也称为“主”线程。还有其他线程在幕后运行,如垃圾收集器,编译器,优化器,终结器等。

快速查看一个没有任何小应用的线程转储:

public static void main(String[] args) throws Exception {
    Thread.sleep(100000);
}

节目:

"Low Memory Detector" daemon prio=5 tid=7f810c801000]
"C2 CompilerThread1" daemon prio=9 tid=7f810c800000
"C2 CompilerThread0" daemon prio=9 tid=7f8107037000
"Signal Dispatcher" daemon prio=9 tid=7f8107036000
"Surrogate Locker Thread (Concurrent GC)" daemon prio=5 tid=7f8107801000 
"Finalizer" daemon prio=8 tid=7f810882a000 nid=0x1118cb000 
"Reference Handler" daemon prio=10 tid=7f8108829000 nid=0x1117c8000 
"main" prio=5 tid=7f8104801000 nid=0x109a52000 waiting on condition
"VM Thread" prio=9 tid=7f8108824800 nid=0x1116c5000 runnable 
"Gang worker#0 (Parallel GC Threads)" prio=9 tid=7f8104802800
"Gang worker#1 (Parallel GC Threads)" prio=9 tid=7f8104803000 
"Gang worker#2 (Parallel GC Threads)" prio=9 tid=7f8104803800 
"Gang worker#3 (Parallel GC Threads)" prio=9 tid=7f8107800000 
"Gang worker#4 (Parallel GC Threads)" prio=9 tid=7f8108800000 
"Gang worker#5 (Parallel GC Threads)" prio=9 tid=7f8107000800
"Gang worker#6 (Parallel GC Threads)" prio=9 tid=7f8107001000
"Gang worker#7 (Parallel GC Threads)" prio=9 tid=7f8107002000 
"Concurrent Mark-Sweep GC Thread" prio=9 tid=7f810701c000
"Gang worker#0 (Parallel CMS Threads)" prio=9 tid=7f81090c3000
"Gang worker#1 (Parallel CMS Threads)" prio=9 tid=7f810701b800
"VM Periodic Task Thread" prio=10 tid=7f810c812800 
"Exception Catcher Thread" prio=10 tid=7f8104801800