Created
December 11, 2020 14:39
-
-
Save dweiss/4787b7aa503ef5702e94d73178c3c842 to your computer and use it in GitHub Desktop.
Repro for IllegalMonitorStateException in ArrayBlockingQueue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.util.concurrent.*; | |
import java.util.stream.*; | |
import java.util.concurrent.atomic.*; | |
public class Repro { | |
public static void main(String[] args) throws Exception { | |
ArrayBlockingQueue<Object> q = new ArrayBlockingQueue<>(1); | |
ForkJoinPool fj = | |
new ForkJoinPool( | |
2, | |
ForkJoinPool.defaultForkJoinWorkerThreadFactory, | |
null, | |
true, | |
0, | |
5, | |
1, | |
null, | |
60_000L, | |
TimeUnit.MILLISECONDS); | |
AtomicBoolean stop = new AtomicBoolean(); | |
for (int i = 0; i < 100; i++) { | |
int j = i; | |
fj.submit( | |
() -> { | |
try { | |
q.put(j); | |
} catch (IllegalMonitorStateException e) { | |
// SHOULD NEVER HAPPEN? But it will. | |
if (!stop.getAndSet(true)) { | |
e.printStackTrace(); | |
System.out.println("fj state: " + fj); | |
System.exit(0); | |
} | |
} catch (InterruptedException e) { | |
} | |
}); | |
} | |
for (int i = 0; i < 100; i++) { | |
System.out.println(": " + q.take() + " " + fj); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment