尝试获取JMH锁时出现异常

8

这段代码之前运行良好。在重新启动电脑后,它给出了以下错误:

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上搜索也无济于事。请问有人知道如何解决这个错误吗?

@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();
}

}


1
你在C盘Windows文件夹中有写入权限吗? - Koustav Ray
2
@SauravSircar 你尝试使用-Djmh.ignoreLock=true了吗?你也可以看看这篇文章 - Alex K
1
你尝试手动删除C:\WINDOWS\/jmh.lock文件了吗? - Alexandre Cartapanis
@AlexandreCartapanis 是的。 - Saurav Sircar
请注意,错误提示为“访问被拒绝”。 - Alexandre Cartapanis
显示剩余4条评论
2个回答

14

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接