< prev index next >

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

Print this page

124     void testPark5() throws Exception {
125         var thread = Thread.ofVirtual().start(() -> {
126             LockSupport.unpark(Thread.currentThread());
127             LockSupport.park();
128         });
129         thread.join();
130     }
131 
132     /**
133      * 2 x unpark before park.
134      */
135     @Test
136     void testPark6() throws Exception {
137         var thread = Thread.ofVirtual().start(() -> {
138             Thread me = Thread.currentThread();
139             LockSupport.unpark(me);
140             LockSupport.unpark(me);
141             LockSupport.park();
142             LockSupport.park();  // should park
143         });
144         Thread.sleep(1000); // give time for thread to park
145         LockSupport.unpark(thread);
146         thread.join();
147     }
148 
149     /**
150      * 2 x park and unpark by platform thread.
151      */
152     @Test
153     void testPark7() throws Exception {
154         var thread = Thread.ofVirtual().start(() -> {
155             LockSupport.park();
156             LockSupport.park();
157         });
158 
159         Thread.sleep(1000); // give time for thread to park
160 
161         // unpark, virtual thread should park again
162         LockSupport.unpark(thread);
163         Thread.sleep(1000);
164         assertTrue(thread.isAlive());

124     void testPark5() throws Exception {
125         var thread = Thread.ofVirtual().start(() -> {
126             LockSupport.unpark(Thread.currentThread());
127             LockSupport.park();
128         });
129         thread.join();
130     }
131 
132     /**
133      * 2 x unpark before park.
134      */
135     @Test
136     void testPark6() throws Exception {
137         var thread = Thread.ofVirtual().start(() -> {
138             Thread me = Thread.currentThread();
139             LockSupport.unpark(me);
140             LockSupport.unpark(me);
141             LockSupport.park();
142             LockSupport.park();  // should park
143         });
144         await(thread, Thread.State.WAITING);
145         LockSupport.unpark(thread);
146         thread.join();
147     }
148 
149     /**
150      * 2 x park and unpark by platform thread.
151      */
152     @Test
153     void testPark7() throws Exception {
154         var thread = Thread.ofVirtual().start(() -> {
155             LockSupport.park();
156             LockSupport.park();
157         });
158 
159         Thread.sleep(1000); // give time for thread to park
160 
161         // unpark, virtual thread should park again
162         LockSupport.unpark(thread);
163         Thread.sleep(1000);
164         assertTrue(thread.isAlive());
< prev index next >