8365893: test/jdk/java/lang/Thread/virtual/JfrEvents.java failing intermittently

Reviewed-by: jpai
This commit is contained in:
Alan Bateman 2025-08-24 16:22:21 +00:00
parent 09aad0aea8
commit 58e7581527

View File

@ -42,6 +42,7 @@ import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.LockSupport;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import jdk.jfr.EventType;
@ -77,12 +78,13 @@ class JfrEvents {
// execute 100 tasks, each in their own virtual thread
recording.start();
ThreadFactory factory = Thread.ofVirtual().factory();
try (var executor = Executors.newThreadPerTaskExecutor(factory)) {
for (int i = 0; i < 100; i++) {
executor.submit(() -> { });
try {
List<Thread> threads = IntStream.range(0, 100)
.mapToObj(_ -> Thread.startVirtualThread(() -> { }))
.toList();
for (Thread t : threads) {
t.join();
}
Thread.sleep(1000); // give time for thread end events to be recorded
} finally {
recording.stop();
}