Runner closes System.out stream

Dmitry Vyazelenko vyazelenko at yahoo.com
Fri Aug 15 19:12:56 UTC 2014


Hi,

I’ve got the problem with JMH 0.9.7 when using Runner API. It appears that System.out stream is being closed once Runner#run() method is executed.

Here is simple benchmark to reproduce:
public class OutStreamClosedBenchmark {
    @Benchmark
    public void dummy() {
    }

    public static void main(String[] args) throws Exception {
        System.out.println("[OUT] BEFORE");
        System.err.println("[ERR] BEFORE.");
        Runner r = new Runner(new OptionsBuilder()
                .forks(1).warmupIterations(0).measurementIterations(1)
                .include(".*OutStreamClosedBenchmark.*")
                .build());
        r.run();
        System.out.println("[OUT] AFTER");
        System.err.println("[ERR] AFTER");
    }
}

And here is the output when executing java -cp target/benchmarks.jar jmh.test.OutStreamClosedBenchmark:
[OUT] BEFORE
[ERR] BEFORE.
# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/bin/java
# VM options: <none>
# Warmup: <none>
# Measurement: 1 iterations, 1 s each
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: jmh.test.OutStreamClosedBenchmark.dummy
...
Benchmark                              Mode  Samples           Score  Score error  Units
j.t.OutStreamClosedBenchmark.dummy    thrpt        1  3573392858.280          NaN  ops/s
[ERR] AFTER

As can be seen the "[OUT] AFTER” is missing in the output.

Best regards,
Dmitry


More information about the jmh-dev mailing list