JMH测试报错:ERROR: Unable to find the resource: /META-INF/BenchmarkList

在学习jmh测试的时候,由于配置问题导致错误。
问题就在于:jmh-generator-annprocess依赖的scope配置为test,此时表示该依赖仅仅在测试阶段会参与进来,包括测试代码的编译,执行。

由于这个依赖并不用于生产,我们可以将scope设置为provided。

<dependency>
            <groupId>org.openjdk.jmh</groupId>
            <artifactId>jmh-generator-annprocess</artifactId>
            <version>1.21</version>
            <scope>provided</scope>
        </dependency>

还有一个错误是出现ERROR: org.openjdk.jmh.runner.RunnerException: ERROR: Exception while trying to acquire the JMH lock (C:\WINDOWS\/jmh.lock): 拒绝访问。, exiting. Use -Djmh.ignoreLock=true to forcefully continue. at org.openjdk.jmh.runner.Runner.run(Runner.java:216) at org.openjdk.jmh.Main.main(Main.java:71)
解决方法是在edit configuration配置
JMH测试报错:ERROR: Unable to find the resource: /META-INF/BenchmarkList_第1张图片
JMH测试报错:ERROR: Unable to find the resource: /META-INF/BenchmarkList_第2张图片
打勾加入系统环境变量即可。
jmh基本注解如下:

    @Benchmark
    @Warmup(iterations = 1,time = 3)//在专业测试里首先要进行预热,预热多少次,预热多少时间
    @Fork(5)//意思是用多少个线程去执行我们的程序
    @BenchmarkMode(Mode.Throughput)//是对基准测试的一个模式,这个模式用的最多的是Throughput吞吐量
    @Measurement(iterations = 1,time = 3)//是整个测试要测试多少遍,调用这个方法要调用多少次

你可能感兴趣的:(java)