File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed
test/jdk/java/lang/Thread/virtual Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change 4242import java .util .concurrent .atomic .AtomicBoolean ;
4343import java .util .concurrent .locks .LockSupport ;
4444import java .util .stream .Collectors ;
45+ import java .util .stream .IntStream ;
4546import java .util .stream .Stream ;
4647
4748import 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 }
You can’t perform that action at this time.
0 commit comments