gpt4 book ai didi

java - 尝试获取 JMH 锁时出现异常

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:38:11 25 4
gpt4 key购买 nike

这段代码运行良好。重新启动计算机时,出现错误:

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

最佳答案

有两种解决方案:

  • 在插件配置中添加 TMP 环境变量并将其指向任何可写目录。 enter image description here

  • 以管理员身份运行idea64.exe

参见 https://github.com/artyushov/idea-jmh-plugin/issues/19

关于java - 尝试获取 JMH 锁时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37720692/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com