< prev index next >

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

Print this page

  1 /*
  2  * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 
 24 /**
 25  * @test
 26  * @summary Basic test for JFR jdk.VirtualThreadXXX events
 27  * @requires vm.continuations
 28  * @modules jdk.jfr java.base/java.lang:+open
 29  * @library /test/lib
 30  * @run junit/othervm --enable-native-access=ALL-UNNAMED JfrEvents
 31  */
 32 
 33 import java.io.IOException;
 34 import java.nio.file.Path;
 35 import java.util.List;
 36 import java.util.Map;
 37 import java.util.concurrent.Executor;
 38 import java.util.concurrent.ExecutorService;
 39 import java.util.concurrent.Executors;
 40 import java.util.concurrent.RejectedExecutionException;
 41 import java.util.concurrent.ThreadFactory;
 42 import java.util.concurrent.atomic.AtomicBoolean;
 43 import java.util.concurrent.atomic.AtomicReference;
 44 import java.util.concurrent.locks.LockSupport;
 45 import java.util.function.Consumer;
 46 import java.util.stream.Collectors;
 47 import java.util.stream.Stream;
 48 
 49 import jdk.jfr.EventType;
 50 import jdk.jfr.Recording;
 51 import jdk.jfr.consumer.RecordedEvent;
 52 import jdk.jfr.consumer.RecordingFile;
 53 
 54 import jdk.test.lib.thread.VThreadPinner;
 55 import jdk.test.lib.thread.VThreadRunner.ThrowingRunnable;
 56 import org.junit.jupiter.api.Test;
 57 import org.junit.jupiter.params.ParameterizedTest;
 58 import org.junit.jupiter.params.provider.Arguments;
 59 import org.junit.jupiter.params.provider.MethodSource;
 60 import static org.junit.jupiter.api.Assertions.*;
 61 
 62 class JfrEvents {
 63 
 64     /**
 65      * Test jdk.VirtualThreadStart and jdk.VirtualThreadEnd events.
 66      */
 67     @Test
 68     void testVirtualThreadStartAndEnd() throws Exception {
 69         try (Recording recording = new Recording()) {
 70             recording.enable("jdk.VirtualThreadStart");
 71             recording.enable("jdk.VirtualThreadEnd");
 72 
 73             // execute 100 tasks, each in their own virtual thread
 74             recording.start();
 75             ThreadFactory factory = Thread.ofVirtual().factory();
 76             try (var executor = Executors.newThreadPerTaskExecutor(factory)) {
 77                 for (int i = 0; i < 100; i++) {
 78                     executor.submit(() -> { });
 79                 }
 80                 Thread.sleep(1000); // give time for thread end events to be recorded
 81             } finally {
 82                 recording.stop();
 83             }
 84 
 85             Map<String, Integer> events = sumEvents(recording);
 86             System.err.println(events);
 87 
 88             int startCount = events.getOrDefault("jdk.VirtualThreadStart", 0);
 89             int endCount = events.getOrDefault("jdk.VirtualThreadEnd", 0);
 90             assertEquals(100, startCount);
 91             assertEquals(100, endCount);
 92         }
 93     }
 94 
 95     /**
 96      * Arguments for testVirtualThreadPinned to test jdk.VirtualThreadPinned event.
 97      *   [0] label/description
 98      *   [1] the operation to park/wait
 99      *   [2] the Thread.State when parked/waiting
100      *   [3] the action to unpark/notify the thread
101      */
102     static Stream<Arguments> pinnedCases() {
103         Object lock = new Object();
104 
105         // park with native frame on stack
106         var finish1 = new AtomicBoolean();
107         var parkWhenPinned = Arguments.of(
108             "LockSupport.park when pinned",
109             (ThrowingRunnable<Exception>) () -> {


110                 VThreadPinner.runPinned(() -> {
111                     while (!finish1.get()) {
112                         LockSupport.park();





113                     }
114                 });
115             },
116             Thread.State.WAITING,
117                 (Consumer<Thread>) t -> {
118                     finish1.set(true);
119                     LockSupport.unpark(t);





































120                 }
121         );







122 
123         // timed park with native frame on stack
124         var finish2 = new AtomicBoolean();
125         var timedParkWhenPinned = Arguments.of(
126             "LockSupport.parkNanos when pinned",
127             (ThrowingRunnable<Exception>) () -> {









128                 VThreadPinner.runPinned(() -> {
129                     while (!finish2.get()) {
130                         LockSupport.parkNanos(Long.MAX_VALUE);









131                     }
132                 });
133             },
134             Thread.State.TIMED_WAITING,
135             (Consumer<Thread>) t -> {
136                 finish2.set(true);
137                 LockSupport.unpark(t);







138             }
139         );
140 
141         return Stream.of(parkWhenPinned, timedParkWhenPinned);

142     }
143 
144     /**
145      * Test jdk.VirtualThreadPinned event.
146      */
147     @ParameterizedTest
148     @MethodSource("pinnedCases")
149     void testVirtualThreadPinned(String label,
150                                  ThrowingRunnable<Exception> parker,
151                                  Thread.State expectedState,
152                                  Consumer<Thread> unparker) throws Exception {




153 
154         try (Recording recording = new Recording()) {
155             recording.enable("jdk.VirtualThreadPinned");






































156 


157             recording.start();







158             try {
159                 var exception = new AtomicReference<Throwable>();
160                 var thread = Thread.ofVirtual().start(() -> {
161                     try {
162                         parker.run();
163                     } catch (Throwable e) {
164                         exception.set(e);
165                     }
166                 });
167                 try {
168                     // wait for thread to park/wait
169                     Thread.State state = thread.getState();
170                     while (state != expectedState) {
171                         assertTrue(state != Thread.State.TERMINATED, thread.toString());
172                         Thread.sleep(10);
173                         state = thread.getState();
174                     }
175                 } finally {
176                     unparker.accept(thread);
177                     thread.join();
178                     assertNull(exception.get());
179                 }
180             } finally {

181                 recording.stop();
182             }
183 
184             Map<String, Integer> events = sumEvents(recording);
185             System.err.println(events);

186 
187             // should have at least one pinned event
188             int pinnedCount = events.getOrDefault("jdk.VirtualThreadPinned", 0);
189             assertTrue(pinnedCount >= 1, "Expected one or more events");

















































190         }
191     }
192 
193     /**
194      * Test jdk.VirtualThreadSubmitFailed event.
195      */
196     @Test
197     void testVirtualThreadSubmitFailed() throws Exception {
198         try (Recording recording = new Recording()) {
199             recording.enable("jdk.VirtualThreadSubmitFailed");
200 
201             recording.start();
202             try (ExecutorService pool = Executors.newCachedThreadPool()) {
203                 Executor scheduler = task -> pool.execute(task);
204 
205                 // create virtual thread that uses custom scheduler
206                 ThreadFactory factory = ThreadBuilders.virtualThreadBuilder(scheduler).factory();
207 
208                 // start a thread
209                 Thread thread = factory.newThread(LockSupport::park);
210                 thread.start();
211 
212                 // wait for thread to park
213                 while (thread.getState() != Thread.State.WAITING) {
214                     Thread.sleep(10);
215                 }
216 
217                 // shutdown scheduler
218                 pool.shutdown();
219 
220                 // unpark, the submit should fail
221                 try {
222                     LockSupport.unpark(thread);
223                     fail();
224                 } catch (RejectedExecutionException expected) { }
225 
226                 // start another thread, it should fail and an event should be recorded
227                 try {
228                     factory.newThread(LockSupport::park).start();
229                     throw new RuntimeException("RejectedExecutionException expected");
230                 } catch (RejectedExecutionException expected) { }
231             } finally {
232                 recording.stop();
233             }
234 
235             Map<String, Integer> events = sumEvents(recording);
236             System.err.println(events);
237 
238             int count = events.getOrDefault("jdk.VirtualThreadSubmitFailed", 0);
239             assertEquals(2, count);
240         }
241     }
242 











243     /**
244      * Read the events from the recording and return a map of event name to count.
245      */
246     private static Map<String, Integer> sumEvents(Recording recording) throws IOException {
247         Path recordingFile = recordingFile(recording);
248         List<RecordedEvent> events = RecordingFile.readAllEvents(recordingFile);
249         return events.stream()
250                 .map(RecordedEvent::getEventType)
251                 .collect(Collectors.groupingBy(EventType::getName,
252                                                Collectors.summingInt(x -> 1)));
253     }
254 
255     /**
256      * Return the file path to the recording file.
257      */
258     private static Path recordingFile(Recording recording) throws IOException {
259         Path recordingFile = recording.getDestination();
260         if (recordingFile == null) {
261             ProcessHandle h = ProcessHandle.current();
262             recordingFile = Path.of("recording-" + recording.getId() + "-pid" + h.pid() + ".jfr");
263             recording.dump(recordingFile);
264         }
265         return recordingFile;
266     }


































267 }

  1 /*
  2  * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 
 24 /**
 25  * @test
 26  * @summary Basic test for JFR jdk.VirtualThreadXXX events
 27  * @requires vm.continuations
 28  * @modules jdk.jfr java.base/java.lang:+open
 29  * @library /test/lib
 30  * @run junit/othervm --enable-native-access=ALL-UNNAMED JfrEvents
 31  */
 32 
 33 import java.io.IOException;
 34 import java.nio.file.Path;
 35 import java.util.List;
 36 import java.util.Map;
 37 import java.util.concurrent.Executor;
 38 import java.util.concurrent.ExecutorService;
 39 import java.util.concurrent.Executors;
 40 import java.util.concurrent.RejectedExecutionException;
 41 import java.util.concurrent.ThreadFactory;
 42 import java.util.concurrent.atomic.AtomicBoolean;

 43 import java.util.concurrent.locks.LockSupport;

 44 import java.util.stream.Collectors;
 45 import java.util.stream.Stream;
 46 
 47 import jdk.jfr.EventType;
 48 import jdk.jfr.Recording;
 49 import jdk.jfr.consumer.RecordedEvent;
 50 import jdk.jfr.consumer.RecordingFile;
 51 
 52 import jdk.test.lib.thread.VThreadPinner;

 53 import org.junit.jupiter.api.Test;
 54 import org.junit.jupiter.params.ParameterizedTest;
 55 import org.junit.jupiter.params.provider.ValueSource;

 56 import static org.junit.jupiter.api.Assertions.*;
 57 
 58 class JfrEvents {
 59 
 60     /**
 61      * Test jdk.VirtualThreadStart and jdk.VirtualThreadEnd events.
 62      */
 63     @Test
 64     void testVirtualThreadStartAndEnd() throws Exception {
 65         try (Recording recording = new Recording()) {
 66             recording.enable("jdk.VirtualThreadStart");
 67             recording.enable("jdk.VirtualThreadEnd");
 68 
 69             // execute 100 tasks, each in their own virtual thread
 70             recording.start();
 71             ThreadFactory factory = Thread.ofVirtual().factory();
 72             try (var executor = Executors.newThreadPerTaskExecutor(factory)) {
 73                 for (int i = 0; i < 100; i++) {
 74                     executor.submit(() -> { });
 75                 }
 76                 Thread.sleep(1000); // give time for thread end events to be recorded
 77             } finally {
 78                 recording.stop();
 79             }
 80 
 81             Map<String, Integer> events = sumEvents(recording);
 82             System.err.println(events);
 83 
 84             int startCount = events.getOrDefault("jdk.VirtualThreadStart", 0);
 85             int endCount = events.getOrDefault("jdk.VirtualThreadEnd", 0);
 86             assertEquals(100, startCount);
 87             assertEquals(100, endCount);
 88         }
 89     }
 90 
 91     /**
 92      * Test jdk.VirtualThreadPinned event when parking while pinned.




 93      */
 94     @ParameterizedTest
 95     @ValueSource(booleans = { true, false })
 96     void testParkWhenPinned(boolean timed) throws Exception {
 97         try (Recording recording = new Recording()) {
 98             recording.enable("jdk.VirtualThreadPinned");
 99             recording.start();
100 
101             var started = new AtomicBoolean();
102             var done = new AtomicBoolean();
103             var vthread = Thread.startVirtualThread(() -> {
104                 VThreadPinner.runPinned(() -> {
105                     started.set(true);
106                     while (!done.get()) {
107                         if (timed) {
108                             LockSupport.parkNanos(Long.MAX_VALUE);
109                         } else {
110                             LockSupport.park();
111                         }
112                     }
113                 });
114             });
115 
116             try {
117                 // wait for thread to start and park
118                 awaitTrue(started);
119                 await(vthread, timed ? Thread.State.TIMED_WAITING : Thread.State.WAITING);
120             } finally {
121                 done.set(true);
122                 LockSupport.unpark(vthread);
123                 vthread.join();
124                 recording.stop();
125             }
126 
127             assertContainsPinnedEvent(recording, vthread);
128         }
129     }
130 
131     /**
132      * Test jdk.VirtualThreadPinned event when blocking on monitor while pinned.
133      */
134     @Test
135     void testBlockWhenPinned() throws Exception {
136         try (Recording recording = new Recording()) {
137             recording.enable("jdk.VirtualThreadPinned");
138             recording.start();
139 
140             Object lock = new Object();
141 
142             var started = new AtomicBoolean();
143             var vthread = Thread.ofVirtual().unstarted(() -> {
144                 VThreadPinner.runPinned(() -> {
145                     started.set(true);
146                     synchronized (lock) { }
147                 });
148             });
149 
150             try {
151                 synchronized (lock) {
152                     vthread.start();
153                     // wait for thread to start and block
154                     awaitTrue(started);
155                     await(vthread, Thread.State.BLOCKED);
156                 }
157             } finally {
158                 vthread.join();
159                 recording.stop();
160             }
161 
162             assertContainsPinnedEvent(recording, vthread);
163         }
164     }
165 
166     /**
167      * Test jdk.VirtualThreadPinned event when waiting with Object.wait while pinned.
168      */
169     @ParameterizedTest
170     @ValueSource(booleans = { true, false })
171     void testObjectWait(boolean timed) throws Exception {
172         try (Recording recording = new Recording()) {
173             recording.enable("jdk.VirtualThreadPinned");
174             recording.start();
175 
176             Object lock = new Object();
177 
178             var started = new AtomicBoolean();
179             var vthread = Thread.startVirtualThread(() -> {
180                 VThreadPinner.runPinned(() -> {
181                     started.set(true);
182                     synchronized (lock) {
183                         try {
184                             if (timed) {
185                                 lock.wait(Long.MAX_VALUE);
186                             } else {
187                                 lock.wait();
188                             }
189                         } catch (InterruptedException e) {
190                             fail();
191                         }
192                     }
193                 });
194             });
195 
196             try {
197                 // wait for thread to start and wait
198                 awaitTrue(started);
199                 await(vthread, timed ? Thread.State.TIMED_WAITING : Thread.State.WAITING);
200             } finally {
201                 synchronized (lock) {
202                     lock.notifyAll();
203                 }
204                 vthread.join();
205                 recording.stop();
206             }

207 
208             assertContainsPinnedEvent(recording, vthread);
209         }
210     }
211 
212     /**
213      * Test jdk.VirtualThreadPinned event when parking in a class initializer.
214      */
215     @Test
216     void testParkInClassInitializer() throws Exception {
217         class TestClass {
218             static {
219                 LockSupport.park();
220             }
221             static void m() {
222                 // do nothing
223             }
224         }
225 
226         try (Recording recording = new Recording()) {
227             recording.enable("jdk.VirtualThreadPinned");
228             recording.start();
229 
230             var started = new AtomicBoolean();
231             Thread vthread = Thread.startVirtualThread(() -> {
232                 started.set(true);
233                 TestClass.m();
234             });
235 
236             try {
237                 // wait for it to start and park
238                 awaitTrue(started);
239                 await(vthread, Thread.State.WAITING);
240             } finally {
241                 LockSupport.unpark(vthread);
242                 vthread.join();
243                 recording.stop();
244             }
245 
246             assertContainsPinnedEvent(recording, vthread);
247         }
248     }
249 
250     /**
251      * Test jdk.VirtualThreadPinned event when blocking on monitor in a class initializer.
252      */
253     @Test
254     void testBlockInClassInitializer() throws Exception {
255         class LockHolder {
256             static final Object lock = new Object();
257         }
258         class TestClass {
259             static {
260                 synchronized (LockHolder.lock) { }
261             }
262             static void m() {
263                 // no nothing
264             }
265         }
266 
267         try (Recording recording = new Recording()) {
268             recording.enable("jdk.VirtualThreadPinned");
269             recording.start();
270 
271             var started = new AtomicBoolean();
272             Thread vthread = Thread.ofVirtual().unstarted(() -> {
273                 started.set(true);
274                 TestClass.m();
275             });
276 
277             try {
278                 synchronized (LockHolder.lock) {
279                     vthread.start();
280                     // wait for thread to start and block
281                     awaitTrue(started);
282                     await(vthread, Thread.State.BLOCKED);















283                 }
284             } finally {
285                 vthread.join();
286                 recording.stop();
287             }
288 
289             assertContainsPinnedEvent(recording, vthread);
290         }
291     }
292 
293     /**
294      * Test jdk.VirtualThreadPinned event when waiting for a class initializer.
295      */
296     @Test
297     void testWaitingForClassInitializer() throws Exception {
298         class TestClass {
299             static {
300                 LockSupport.park();
301             }
302             static void m() {
303                 // do nothing
304             }
305         }
306 
307         try (Recording recording = new Recording()) {
308             recording.enable("jdk.VirtualThreadPinned");
309             recording.start();
310 
311             var started1 = new AtomicBoolean();
312             var started2 = new AtomicBoolean();
313 
314             Thread vthread1 =  Thread.ofVirtual().unstarted(() -> {
315                 started1.set(true);
316                 TestClass.m();
317             });
318             Thread vthread2 = Thread.ofVirtual().unstarted(() -> {
319                 started2.set(true);
320                 TestClass.m();
321             });
322 
323             try {
324                 // start first virtual thread and wait for it to start + park
325                 vthread1.start();
326                 awaitTrue(started1);
327                 await(vthread1, Thread.State.WAITING);
328 
329                 // start second virtual thread and wait for it to start
330                 vthread2.start();
331                 awaitTrue(started2);
332 
333                 // give time for second virtual thread to wait on the MutexLocker
334                 Thread.sleep(3000);
335 
336             } finally {
337                 LockSupport.unpark(vthread1);
338                 vthread1.join();
339                 vthread2.join();
340                 recording.stop();
341             }
342 
343             // the recording should have a pinned event for vthread2
344             assertContainsPinnedEvent(recording, vthread2);
345         }
346     }
347 
348     /**
349      * Test jdk.VirtualThreadSubmitFailed event.
350      */
351     @Test
352     void testVirtualThreadSubmitFailed() throws Exception {
353         try (Recording recording = new Recording()) {
354             recording.enable("jdk.VirtualThreadSubmitFailed");
355 
356             recording.start();
357             try (ExecutorService pool = Executors.newCachedThreadPool()) {
358                 Executor scheduler = task -> pool.execute(task);
359 
360                 // create virtual thread that uses custom scheduler
361                 ThreadFactory factory = ThreadBuilders.virtualThreadBuilder(scheduler).factory();
362 
363                 // start a thread
364                 Thread thread = factory.newThread(LockSupport::park);
365                 thread.start();
366 
367                 // wait for thread to park
368                 await(thread, Thread.State.WAITING);


369 
370                 // shutdown scheduler
371                 pool.shutdown();
372 
373                 // unpark, the submit should fail
374                 try {
375                     LockSupport.unpark(thread);
376                     fail();
377                 } catch (RejectedExecutionException expected) { }
378 
379                 // start another thread, it should fail and an event should be recorded
380                 try {
381                     factory.newThread(LockSupport::park).start();
382                     throw new RuntimeException("RejectedExecutionException expected");
383                 } catch (RejectedExecutionException expected) { }
384             } finally {
385                 recording.stop();
386             }
387 
388             List<RecordedEvent> submitFailedEvents = find(recording, "jdk.VirtualThreadSubmitFailed");
389             System.err.println(submitFailedEvents);
390             assertTrue(submitFailedEvents.size() == 2, "Expected two events");


391         }
392     }
393 
394     /**
395      * Returns the list of events in the given recording with the given name.
396      */
397     private static List<RecordedEvent> find(Recording recording, String name) throws IOException {
398         Path recordingFile = recordingFile(recording);
399         return RecordingFile.readAllEvents(recordingFile)
400                 .stream()
401                 .filter(e -> e.getEventType().getName().equals(name))
402                 .toList();
403     }
404 
405     /**
406      * Read the events from the recording and return a map of event name to count.
407      */
408     private static Map<String, Integer> sumEvents(Recording recording) throws IOException {
409         Path recordingFile = recordingFile(recording);
410         List<RecordedEvent> events = RecordingFile.readAllEvents(recordingFile);
411         return events.stream()
412                 .map(RecordedEvent::getEventType)
413                 .collect(Collectors.groupingBy(EventType::getName,
414                                                Collectors.summingInt(x -> 1)));
415     }
416 
417     /**
418      * Return the file path to the recording file.
419      */
420     private static Path recordingFile(Recording recording) throws IOException {
421         Path recordingFile = recording.getDestination();
422         if (recordingFile == null) {
423             ProcessHandle h = ProcessHandle.current();
424             recordingFile = Path.of("recording-" + recording.getId() + "-pid" + h.pid() + ".jfr");
425             recording.dump(recordingFile);
426         }
427         return recordingFile;
428     }
429 
430     /**
431      * Assert that a recording contains a jdk.VirtualThreadPinned event on the given thread.
432      */
433     private void assertContainsPinnedEvent(Recording recording, Thread thread) throws IOException {
434         List<RecordedEvent> pinnedEvents = find(recording, "jdk.VirtualThreadPinned");
435         assertTrue(pinnedEvents.size() > 0, "No jdk.VirtualThreadPinned events in recording");
436         System.err.println(pinnedEvents);
437 
438         long tid = thread.threadId();
439         assertTrue(pinnedEvents.stream()
440                         .anyMatch(e -> e.getThread().getJavaThreadId() == tid),
441                 "jdk.VirtualThreadPinned for javaThreadId = " + tid + " not found");
442     }
443 
444     /**
445      * Waits for the given boolean to be set to true.
446      */
447     private void awaitTrue(AtomicBoolean b) throws InterruptedException {
448         while (!b.get()) {
449             Thread.sleep(10);
450         }
451     }
452 
453     /**
454      * Waits for the given thread to reach a given state.
455      */
456     private static void await(Thread thread, Thread.State expectedState) throws InterruptedException {
457         Thread.State state = thread.getState();
458         while (state != expectedState) {
459             Thread.sleep(10);
460             state = thread.getState();
461         }
462     }
463 }
< prev index next >