2016-02-12 61 views
1

如何避免jvm运行jvm容器中的编译器线程。如何避免jvm容器中运行编译器线程

"C1 CompilerThread1" #6 daemon prio=9 os_prio=0 tid=0x00007fb2980cc000 nid=0x440e waiting on condition [0x0000000000000000] 
    java.lang.Thread.State: RUNNABLE 

"C2 CompilerThread0" #5 daemon prio=9 os_prio=0 tid=0x00007fb2980be800 nid=0x440d waiting on condition [0x0000000000000000] 
    java.lang.Thread.State: RUNNABLE 
+0

为什么你想避免他们? –

回答

2

那些线程来自热点编译器。如果您想在线程转储中删除它们,请以java -Xint ...开始您的应用程序。

被警告后可能会缓慢运行。 ;-)

编辑要说清楚。禁用JIT编译器不是你想要做的事情。然后字节码在interpreted模式下执行,而不是compiled code for your plattform。看到java options

小片段演示

public class Jit { 
    public static void main(String[] args) { 
     long start = System.currentTimeMillis(); 
     StringBuilder sb = new StringBuilder(); 
     for (int i = 0; i < 10_000_000; i++) { 
      sb.append(' '); 
     } 
     long end = System.currentTimeMillis(); 
     System.out.println("length = " + sb.length()); 
     System.out.println("duration: " + (end - start)); 
    } 
} 

在混合模式下运行(编译点播)

java Jit 
length = 10000000 
duration: 124 

运行在解释模式下

java -Xint Jit 
length = 10000000 
duration: 3495 
+1

可能吗?将!一个数量级! –

+0

@StephenC我知道。因此,笑脸。 – SubOptimal

+0

我知道你知道。但是OP可能不会“得到”你的幽默感。 –