2626import jdk .test .lib .process .OutputAnalyzer ;
2727import org .junit .Test ;
2828
29- import java .util .concurrent .CountDownLatch ;
3029import java .util .concurrent .atomic .AtomicBoolean ;
3130import java .util .regex .Pattern ;
3231
@@ -41,16 +40,18 @@ public class PrintMountedVirtualThread {
4140
4241 public void run (CommandExecutor executor ) throws InterruptedException {
4342 var shouldFinish = new AtomicBoolean (false );
44- var started = new CountDownLatch ( 1 );
43+ var started = new AtomicBoolean ( );
4544 final Runnable runnable = new DummyRunnable (shouldFinish , started );
4645 try {
4746 Thread vthread = Thread .ofVirtual ().name ("Dummy Vthread" ).start (runnable );
48- started .await ();
47+ while (!started .get ()) {
48+ Thread .sleep (10 );
49+ }
4950 /* Execute */
5051 OutputAnalyzer output = executor .execute ("Thread.print" );
5152 output .shouldMatch (".*at " + Pattern .quote (DummyRunnable .class .getName ()) + "\\ .run.*" );
5253 output .shouldMatch (".*at " + Pattern .quote (DummyRunnable .class .getName ()) + "\\ .compute.*" );
53- output .shouldMatch ("Mounted virtual thread " + "\" Dummy Vthread \" " + " #" + vthread .threadId ());
54+ output .shouldMatch ("Mounted virtual thread " + "#" + vthread .threadId ());
5455
5556 } finally {
5657 shouldFinish .set (true );
@@ -63,11 +64,10 @@ public void jmx() throws InterruptedException {
6364 }
6465
6566 static class DummyRunnable implements Runnable {
66-
6767 private final AtomicBoolean shouldFinish ;
68- private final CountDownLatch started ;
68+ private final AtomicBoolean started ;
6969
70- public DummyRunnable (AtomicBoolean shouldFinish , CountDownLatch started ) {
70+ public DummyRunnable (AtomicBoolean shouldFinish , AtomicBoolean started ) {
7171 this .shouldFinish = shouldFinish ;
7272 this .started = started ;
7373 }
@@ -77,12 +77,11 @@ public void run() {
7777 }
7878
7979 void compute () {
80- started .countDown ( );
80+ started .set ( true );
8181 while (!shouldFinish .get ()) {
8282 Thread .onSpinWait ();
8383 }
8484 }
8585 }
8686
87-
8887}
0 commit comments