Skip to content

Commit

Permalink
8311989: Test java/lang/Thread/virtual/Reflection.java timed out
Browse files Browse the repository at this point in the history
Backport-of: 6faf05c6ddb3a0bcf4dce9516b8fca15d25cd80f
  • Loading branch information
Andrew Lu committed Jun 4, 2024
1 parent 481b42f commit 82adc56
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions test/jdk/java/lang/Thread/virtual/Reflection.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
Expand Down Expand Up @@ -146,15 +147,19 @@ void testInvokeStatic6() throws Exception {
try (ExecutorService scheduler = Executors.newFixedThreadPool(1)) {
Thread.Builder builder = ThreadBuilders.virtualThreadBuilder(scheduler);
ThreadFactory factory = builder.factory();

var ready = new CountDownLatch(1);
Thread vthread = factory.newThread(() -> {
ready.countDown();
try {
parkMethod.invoke(null); // blocks
} catch (Exception e) { }
});
vthread.start();

try {
// give thread time to be scheduled
Thread.sleep(100);
// wait for thread to run
ready.await();

// unpark with another virtual thread, runs on same carrier thread
Thread unparker = factory.newThread(() -> LockSupport.unpark(vthread));
Expand Down Expand Up @@ -321,17 +326,27 @@ void testNewInstance6() throws Exception {
try (ExecutorService scheduler = Executors.newFixedThreadPool(1)) {
Thread.Builder builder = ThreadBuilders.virtualThreadBuilder(scheduler);
ThreadFactory factory = builder.factory();

var ready = new CountDownLatch(1);
Thread vthread = factory.newThread(() -> {
ready.countDown();
try {
ctor.newInstance();
} catch (Exception e) { }
});
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
factory.newThread(() -> LockSupport.unpark(vthread)).start();
// unpark with another virtual thread, runs on same carrier thread
Thread unparker = factory.newThread(() -> LockSupport.unpark(vthread));
unparker.start();
unparker.join();
} finally {
LockSupport.unpark(vthread); // in case test fails
}
}
}

Expand Down

1 comment on commit 82adc56

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.