Skip to content

Commit 58e7581

Browse files
author
Alan Bateman
committed
8365893: test/jdk/java/lang/Thread/virtual/JfrEvents.java failing intermittently
Reviewed-by: jpai
1 parent 09aad0a commit 58e7581

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

test/jdk/java/lang/Thread/virtual/JfrEvents.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.util.concurrent.atomic.AtomicBoolean;
4343
import java.util.concurrent.locks.LockSupport;
4444
import java.util.stream.Collectors;
45+
import java.util.stream.IntStream;
4546
import java.util.stream.Stream;
4647

4748
import jdk.jfr.EventType;
@@ -77,12 +78,13 @@ void testVirtualThreadStartAndEnd() throws Exception {
7778

7879
// execute 100 tasks, each in their own virtual thread
7980
recording.start();
80-
ThreadFactory factory = Thread.ofVirtual().factory();
81-
try (var executor = Executors.newThreadPerTaskExecutor(factory)) {
82-
for (int i = 0; i < 100; i++) {
83-
executor.submit(() -> { });
81+
try {
82+
List<Thread> threads = IntStream.range(0, 100)
83+
.mapToObj(_ -> Thread.startVirtualThread(() -> { }))
84+
.toList();
85+
for (Thread t : threads) {
86+
t.join();
8487
}
85-
Thread.sleep(1000); // give time for thread end events to be recorded
8688
} finally {
8789
recording.stop();
8890
}

0 commit comments

Comments
 (0)