8311989: Test java/lang/Thread/virtual/Reflection.java timed out
Reviewed-by: jpai, mchung
This commit is contained in:
parent
5d1b911c92
commit
6faf05c6dd
@ -32,6 +32,7 @@
|
|||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ThreadFactory;
|
import java.util.concurrent.ThreadFactory;
|
||||||
@ -146,15 +147,19 @@ class Reflection {
|
|||||||
try (ExecutorService scheduler = Executors.newFixedThreadPool(1)) {
|
try (ExecutorService scheduler = Executors.newFixedThreadPool(1)) {
|
||||||
Thread.Builder builder = ThreadBuilders.virtualThreadBuilder(scheduler);
|
Thread.Builder builder = ThreadBuilders.virtualThreadBuilder(scheduler);
|
||||||
ThreadFactory factory = builder.factory();
|
ThreadFactory factory = builder.factory();
|
||||||
|
|
||||||
|
var ready = new CountDownLatch(1);
|
||||||
Thread vthread = factory.newThread(() -> {
|
Thread vthread = factory.newThread(() -> {
|
||||||
|
ready.countDown();
|
||||||
try {
|
try {
|
||||||
parkMethod.invoke(null); // blocks
|
parkMethod.invoke(null); // blocks
|
||||||
} catch (Exception e) { }
|
} catch (Exception e) { }
|
||||||
});
|
});
|
||||||
vthread.start();
|
vthread.start();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// give thread time to be scheduled
|
// wait for thread to run
|
||||||
Thread.sleep(100);
|
ready.await();
|
||||||
|
|
||||||
// unpark with another virtual thread, runs on same carrier thread
|
// unpark with another virtual thread, runs on same carrier thread
|
||||||
Thread unparker = factory.newThread(() -> LockSupport.unpark(vthread));
|
Thread unparker = factory.newThread(() -> LockSupport.unpark(vthread));
|
||||||
@ -321,17 +326,27 @@ class Reflection {
|
|||||||
try (ExecutorService scheduler = Executors.newFixedThreadPool(1)) {
|
try (ExecutorService scheduler = Executors.newFixedThreadPool(1)) {
|
||||||
Thread.Builder builder = ThreadBuilders.virtualThreadBuilder(scheduler);
|
Thread.Builder builder = ThreadBuilders.virtualThreadBuilder(scheduler);
|
||||||
ThreadFactory factory = builder.factory();
|
ThreadFactory factory = builder.factory();
|
||||||
|
|
||||||
|
var ready = new CountDownLatch(1);
|
||||||
Thread vthread = factory.newThread(() -> {
|
Thread vthread = factory.newThread(() -> {
|
||||||
|
ready.countDown();
|
||||||
try {
|
try {
|
||||||
ctor.newInstance();
|
ctor.newInstance();
|
||||||
} catch (Exception e) { }
|
} catch (Exception e) { }
|
||||||
});
|
});
|
||||||
vthread.start();
|
vthread.start();
|
||||||
|
|
||||||
Thread.sleep(100); // give thread time to be scheduled
|
try {
|
||||||
|
// wait for thread to run
|
||||||
|
ready.await();
|
||||||
|
|
||||||
// unpark with another virtual thread, runs on same carrier thread
|
// unpark with another virtual thread, runs on same carrier thread
|
||||||
factory.newThread(() -> LockSupport.unpark(vthread)).start();
|
Thread unparker = factory.newThread(() -> LockSupport.unpark(vthread));
|
||||||
|
unparker.start();
|
||||||
|
unparker.join();
|
||||||
|
} finally {
|
||||||
|
LockSupport.unpark(vthread); // in case test fails
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user