8287200: Test java/lang/management/ThreadMXBean/VirtualThreadDeadlocks.java timed out after JDK-8287103
Reviewed-by: kevinw, cjplummer, alanb
This commit is contained in:
parent
ec97da93c1
commit
176bb23de1
@ -35,13 +35,14 @@
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.ThreadMXBean;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.CyclicBarrier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class VirtualThreadDeadlocks {
|
||||
private static final Object LOCK1 = new Object();
|
||||
private static final Object LOCK2 = new Object();
|
||||
|
||||
private static volatile boolean lock2Held;
|
||||
private static final CyclicBarrier barrier = new CyclicBarrier(2);
|
||||
|
||||
/**
|
||||
* PP = test deadlock with two platform threads
|
||||
@ -56,9 +57,7 @@ public class VirtualThreadDeadlocks {
|
||||
: Thread.ofVirtual();
|
||||
Thread thread1 = builder1.start(() -> {
|
||||
synchronized (LOCK1) {
|
||||
while (!lock2Held) {
|
||||
try { Thread.sleep(10); } catch (Exception e) { }
|
||||
}
|
||||
try { barrier.await(); } catch (Exception ie) {}
|
||||
synchronized (LOCK2) { }
|
||||
}
|
||||
});
|
||||
@ -70,7 +69,7 @@ public class VirtualThreadDeadlocks {
|
||||
: Thread.ofVirtual();
|
||||
Thread thread2 = builder2.start(() -> {
|
||||
synchronized (LOCK2) {
|
||||
lock2Held = true;
|
||||
try { barrier.await(); } catch (Exception ie) {}
|
||||
synchronized (LOCK1) { }
|
||||
}
|
||||
});
|
||||
@ -98,6 +97,9 @@ public class VirtualThreadDeadlocks {
|
||||
private static void awaitBlocked(Thread thread) throws InterruptedException {
|
||||
while (thread.getState() != Thread.State.BLOCKED) {
|
||||
Thread.sleep(10);
|
||||
if (!thread.isAlive()) {
|
||||
throw new RuntimeException("Thread " + thread + " is terminated.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user