JMH使用“选项”构建器

时间:2016-09-26 19:18:08

标签: java jmh

我正在运行JMH基准测试:

         Options opt = new OptionsBuilder()
                .output("C:/test/infinispan/benchmarkThr" + THREAD_COUNT + ".txt")
                .include(InfinispanFileStoreCreateUpdateGetBenchmark.class.getSimpleName())
                .include(InfinispanMemoryCreateUpdateGetBenchmark.class.getSimpleName())
                //.jvmArgsPrepend("-Xms1024m -Xmx1024m")
                .warmupIterations(0)
                .measurementIterations(INTERATIONS)
                .timeUnit(TimeUnit.MILLISECONDS)
                .mode(Mode.SingleShotTime)
                .threads(THREAD_COUNT)
                .forks(1)
                .build();

        new Runner(opt).run();

我得到OutOfMemoryError。我想添加更多(注释掉的文本),但我发现一个对我来说很奇怪的错误(这应该是IMO的工作):

# Run progress: 0,00% complete, ETA 00:16:40
# Fork: 1 of 1
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Invalid initial heap size: -Xms1024M -Xmx1124M

如何成功添加内存?

1 个答案:

答案 0 :(得分:2)

使用2 String而不是下一个参数分别提供每个参数:

...
.jvmArgs("-Xms1024m", "-Xmx1024m")
...