此代码工作正常。重新启动计算机时,它给出了错误:
ERROR: org.openjdk.jmh.runner.RunnerException:
ERROR: Exception while trying to acquire the JMH lock (C:\WINDOWS\/jmh.lock):
Access is denied, exiting. Use -Djmh.ignoreLock=true to forcefully continue.
at org.openjdk.jmh.runner.Runner.run(Runner.java:213)
at org.openjdk.jmh.Main.main(Main.java:71)
Google-int错误没有帮助。有人能告诉我如何解决它吗?
@State(Scope.Thread)
public class test {
public ConcurrentHashMap<String,Integer> i = new ConcurrentHashMap<String, Integer>(10000);
public ArrayList<String> k = new ArrayList<String>(10000);
public int p=0;
public void setup(){
for(int m=0;m<1000;m++){
int j=ThreadLocalRandom.current().nextInt(0,10000);
String jk=Integer.toString(j);
k.add(jk);
i.put(jk,j);
}
}
@Benchmark
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@Warmup(iterations = 3)
@Measurement(iterations = 5)
public void putKey(){
int n=ThreadLocalRandom.current().nextInt(0,10000);
String nk=Integer.toString(n);
k.add(nk);
i.put(nk,n);
}
@Benchmark
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@Warmup(iterations = 3)
@Measurement(iterations = 5)
public int getKey(){
p=ThreadLocalRandom.current().nextInt(0,10000);
p=p%k.size();
return i.get(k.get(p));
}
public static void main(String[] args) throws RunnerException{
Options opt = new OptionsBuilder()
.include(".*" + test.class.getSimpleName() + ".*")
.forks(1)
.build();
new Runner(opt).run();
}
}
答案 0 :(得分:13)
有两种解决方案:
答案 1 :(得分:0)
我在Windows上使用Gradle(命令行)遇到了同样的错误消息。 (我需要传递--stacktrace
来查找根本原因错误消息。)
在我看来,这是由于以下问题引起的:
https://github.com/artyushov/idea-jmh-plugin/issues/19
解决方案就是简单地修改jmh-gradle-plugin
的版本。此处记录了最低要求的版本: