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

时间:2016-02-12 12:37:29

标签: java multithreading 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

1 个答案:

答案 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