8071641: java/lang/management/ThreadMXBean/SynchronizationStatistics.java intermittently failed with NPE
authorjbachorik
Fri, 30 Jan 2015 22:01:32 +0100
changeset 28857 20499c662815
parent 28768 30b987a20989
child 28858 ea6b89a1b59b
8071641: java/lang/management/ThreadMXBean/SynchronizationStatistics.java intermittently failed with NPE Reviewed-by: sjiang, dfuchs
jdk/test/java/lang/management/ThreadMXBean/SynchronizationStatistics.java
--- a/jdk/test/java/lang/management/ThreadMXBean/SynchronizationStatistics.java	Thu Jan 29 03:54:45 2015 +0000
+++ b/jdk/test/java/lang/management/ThreadMXBean/SynchronizationStatistics.java	Fri Jan 30 22:01:32 2015 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -75,7 +75,7 @@
     }
 
     private static void waitForThreadState(Thread t, Thread.State state) throws InterruptedException {
-        while (!t.isInterrupted() && t.getState() != state) {
+        while (t.getState() != state) {
             Thread.sleep(3);
         }
     }
@@ -109,7 +109,9 @@
         synchronized(lock1) {
             p.arriveAndAwaitAdvance(); // phase[1]
             waitForThreadState(lt, Thread.State.BLOCKED);
-            lockName = mbean.getThreadInfo(tid).getLockName();
+            do {
+                lockName = mbean.getThreadInfo(tid).getLockName();
+            } while (lockName == null);
         }
 
         p.arriveAndAwaitAdvance(); // phase[2]
@@ -159,7 +161,9 @@
         synchronized(lock1) {
             p.arriveAndAwaitAdvance(); // phase[1]
             waitForThreadState(lt, Thread.State.BLOCKED);
-            lockName = mbean.getThreadInfo(tid).getLockName();
+            do {
+                lockName = mbean.getThreadInfo(tid).getLockName();
+            } while (lockName == null);
         }
         p.arriveAndAwaitAdvance(); // phase[2]
 
@@ -168,7 +172,9 @@
         synchronized(lock2) {
             p.arriveAndAwaitAdvance(); // phase [3]
             waitForThreadState(lt, Thread.State.BLOCKED);
-            lockName = mbean.getThreadInfo(tid).getLockName();
+            do {
+                lockName = mbean.getThreadInfo(tid).getLockName();
+            } while (lockName == null);
         }
         p.arriveAndAwaitAdvance(); // phase [4]
         testBlocked(ti, () -> mbean.getThreadInfo(tid), lockName, lock2);