Exception while trying to acquire a JMH lock
Asked Answered
M

2

8

This code was working fine. On restarting the computer, it gives me the error:

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 the error didn't help. Can someone tell me how to fix it?

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

}

Marcimarcia answered 9/6, 2016 at 8:31 Comment(9)
Do you have write permissions in your c drive windows folder?Piatt
@SauravSircar Did you try use -Djmh.ignoreLock=true? You can also look at this postMoneymaking
Have you tried do manually delete the C:\WINDOWS\/jmh.lock file ?Koran
@KoustavRay How do I do that? Sorry I'm quite new at Java.Marcimarcia
@AlexandreCartapanis I'm unable to find it.Marcimarcia
tried to show hidden files ?Koran
@AlexandreCartapanis Yup.Marcimarcia
Note that the error says "access denied"Koran
Try creating a new file in that same locationPiatt
F
14

There are 2 solutions:

  • add the TMP environment variable in the plugin configuration and point it to any writeable directory. enter image description here

  • run idea64.exe as Administrator

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

Fusionism answered 18/9, 2016 at 21:15 Comment(0)
S
0

I encountered this same error message using the Gradle (command-line) on Windows. (I needed to pass --stacktrace to find the root-cause error message.)

In my case it was due to the following issue:

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

And the solution was simply to bump the version of the jmh-gradle-plugin. Minimum required versions are documented here:

https://github.com/melix/jmh-gradle-plugin

Scary answered 6/11, 2018 at 21:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.