文章詳情頁
簡單的Java示例以14個線程運行。為什么?
瀏覽:89日期:2024-05-06 14:46:16
如何解決簡單的Java示例以14個線程運行。為什么??
默認情況下,我的JVM(1.6.0_26)產生更多線程。大多數都具有漂亮的描述性名稱,以暗示其目的:
@H_404_2@'Attach Listener' daemon prio=10 tid=0x0000000041426800 nid=0x2fb9 waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE'Low Memory Detector' daemon prio=10 tid=0x00007f512c07e800 nid=0x2fa3 runnable [0x0000000000000000] java.lang.Thread.State: RUNNABLE'C2 CompilerThread1' daemon prio=10 tid=0x00007f512c07b800 nid=0x2fa2 waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE'C2 CompilerThread0' daemon prio=10 tid=0x00007f512c078800 nid=0x2fa1 waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE'Signal dispatcher' daemon prio=10 tid=0x00007f512c076800 nid=0x2fa0 runnable [0x0000000000000000] java.lang.Thread.State: RUNNABLE'Finalizer' daemon prio=10 tid=0x00007f512c05a000 nid=0x2f9f in Object.wait() [0x00007f512b8f7000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x00000007c14b1300> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:118) - locked <0x00000007c14b1300> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:134) at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159)'Reference Handler' daemon prio=10 tid=0x00007f512c058000 nid=0x2f9e in Object.wait() [0x00007f512b9f8000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x00000007c14b11d8> (a java.lang.ref.Reference$Lock) at java.lang.Object.wait(Object.java:485) at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:116) - locked <0x00000007c14b11d8> (a java.lang.ref.Reference$Lock)'main' prio=10 tid=0x0000000041401800 nid=0x2f94 waiting on condition [0x00007f5135735000] java.lang.Thread.State: TIMED_WAITING (sleeping) at java.lang.Thread.sleep(Native Method) at Main.main(Main.java:5)'VM Thread' prio=10 tid=0x00007f512c051800 nid=0x2f9d runnable'GC task thread#0 (ParallelGC)' prio=10 tid=0x0000000041414800 nid=0x2f95 runnable'GC task thread#1 (ParallelGC)' prio=10 tid=0x00007f512c001000 nid=0x2f96 runnable'GC task thread#2 (ParallelGC)' prio=10 tid=0x00007f512c002800 nid=0x2f97 runnable'GC task thread#3 (ParallelGC)' prio=10 tid=0x00007f512c004800 nid=0x2f98 runnable'GC task thread#4 (ParallelGC)' prio=10 tid=0x00007f512c006800 nid=0x2f99 runnable'GC task thread#5 (ParallelGC)' prio=10 tid=0x00007f512c008000 nid=0x2f9a runnable'GC task thread#6 (ParallelGC)' prio=10 tid=0x00007f512c00a000 nid=0x2f9b runnable'GC task thread#7 (ParallelGC)' prio=10 tid=0x00007f512c00c000 nid=0x2f9c runnable'VM Periodic Task Thread' prio=10 tid=0x00007f512c089000 nid=0x2fa4 waiting on condition顯然,大多數線程與內存處理有關:有8個垃圾收集器線程,外加低內存檢測器。Finalizer和ReferenceHandler聽起來像他們也參與了內存管理。
C2 CompilerThread0/1 幾乎可以肯定,它與即時編譯有關。
至于其余線程的確切目的,我不確定。
解決方法以下簡單的Java代碼:
public class Main { public static void main(String[] args) throws InterruptedException {System.out.println('Start');Thread.sleep(5000);System.out.println('Done'); }}
使用14個線程運行。我知道在后臺運行一些GC線程,但是其他線程又有什么用?為什么會有這么多線程?我在使用Java 1.6.0_26的GentooLinux上。使用Eclipse的編譯器或javac進行編譯沒有任何區別(在Eclipse的調試模式下運行它會增加3個線程,但這可能是合理的)。
標簽:
java
相關文章:
1. python的文件讀寫問題?2. javascript - h5上的手機號默認沒有識別3. mysql里的大表用mycat做水平拆分,是不是要先手動分好,再配置mycat4. javascript - 圖片鏈接請求一直是pending狀態,導致頁面崩潰,怎么解決?5. javascript - 關于圣杯布局的一點疑惑6. python - 獲取到的數據生成新的mysql表7. javascript - 請問 chrome 為什么會重復加載圖片資源?8. window下mysql中文亂碼怎么解決??9. javascript - jquery hide()方法無效10. 怎么用css截取字符?
排行榜
