文章详情页
简单的Java示例以14个线程运行。为什么?
如何解决简单的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. javascript - 引入 simditor,但是显示标签,这个怎么解决。2. android - 目前有哪些用Vue.js开发移动App的方案?3. 为什么要通过常量的方式拐弯抹角的写呢,直接写DSN之类的不好吗4. python 发邮件5. python - 关于flask 静态文件配置404的问题6. defined这个实验代码我这里不对哇7. android - 安卓实现类似QQ刚换聊天背景的功能8. python - scrapy获取网页指定内容,后翻到下一页继续,固定循环次数。。问题9. javascript - easyui textbox绑定onchange事件不能获取最新的文本框的值10. javascript - 仿着echarts官网的地图做了个例子,但是只显示出来了地点,没有画出飞机动态效果??急
排行榜