8076050: java/lang/management/ThreadMXBean/ThreadMXBeanStateTest.java fails intermittently
authorjbachorik
Mon, 13 Apr 2015 09:43:12 +0200
changeset 30352 551e7993450a
parent 30351 94434dd8dc9f
child 30353 d831fae73de9
8076050: java/lang/management/ThreadMXBean/ThreadMXBeanStateTest.java fails intermittently Reviewed-by: sla
jdk/test/java/lang/Thread/ThreadStateController.java
jdk/test/java/lang/management/ThreadMXBean/ThreadMXBeanStateTest.java
--- a/jdk/test/java/lang/Thread/ThreadStateController.java	Thu Apr 09 09:18:56 2015 +0200
+++ b/jdk/test/java/lang/Thread/ThreadStateController.java	Mon Apr 13 09:43:12 2015 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2014 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -28,6 +28,7 @@
 import java.util.concurrent.locks.LockSupport;
 
 import jdk.testlibrary.LockFreeLogManager;
+import jdk.testlibrary.Utils;
 
 /**
  * ThreadStateController allows a thread to request this thread to transition
@@ -73,7 +74,7 @@
 
     public static void pause(long ms) {
         try {
-            Thread.sleep(ms);
+            Thread.sleep(Utils.adjustTimeout(ms));
         } catch (InterruptedException e) {
             throw new RuntimeException(e);
         }
@@ -135,7 +136,7 @@
                         try {
                             // this thread has escaped the BLOCKED state
                             // release the lock and a short wait before continue
-                            lock.wait(10);
+                            lock.wait(Utils.adjustTimeout(10));
                         } catch (InterruptedException e) {
                             // ignore
                             interrupted.incrementAndGet();
@@ -165,7 +166,7 @@
                             getId(), getName(), iterations.get(), interrupted.get());
                         try {
                             stateChange(nextState);
-                            lock.wait(10000);
+                            lock.wait(Integer.MAX_VALUE);
                             log("%d:   %s wakes up from timed waiting (iterations %d interrupted %d)%n",
                                 getId(), getName(), iterations.get(), interrupted.get());
                         } catch (InterruptedException e) {
@@ -185,7 +186,8 @@
                 case S_TIMED_PARKED: {
                     log("%d: %s is going to timed park (iterations %d)%n",
                         getId(), getName(), iterations.get());
-                    long deadline = System.currentTimeMillis() + 10000*1000;
+                    long deadline = System.currentTimeMillis() +
+                                        Utils.adjustTimeout(10000*1000);
                     stateChange(nextState);
                     LockSupport.parkUntil(deadline);
                     break;
@@ -195,7 +197,7 @@
                         getId(), getName(), iterations.get(), interrupted.get());
                     try {
                         stateChange(nextState);
-                        Thread.sleep(1000000);
+                        Thread.sleep(Utils.adjustTimeout(1000000));
                     } catch (InterruptedException e) {
                         // finish sleeping
                         interrupted.incrementAndGet();
--- a/jdk/test/java/lang/management/ThreadMXBean/ThreadMXBeanStateTest.java	Thu Apr 09 09:18:56 2015 +0200
+++ b/jdk/test/java/lang/management/ThreadMXBean/ThreadMXBeanStateTest.java	Mon Apr 13 09:43:12 2015 +0200
@@ -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
@@ -64,60 +64,61 @@
         Thread.currentThread().getState();
         ThreadStateController thread = new ThreadStateController("StateChanger", globalLock);
         thread.setDaemon(true);
-
-        // before myThread starts
-        thread.checkThreadState(NEW);
+        try {
+            // before myThread starts
+            thread.checkThreadState(NEW);
 
-        thread.start();
-        thread.transitionTo(RUNNABLE);
-        thread.checkThreadState(RUNNABLE);
-        checkLockInfo(thread, RUNNABLE, null, null);
+            thread.start();
+            thread.transitionTo(RUNNABLE);
+            thread.checkThreadState(RUNNABLE);
+            checkLockInfo(thread, RUNNABLE, null, null);
 
-        thread.suspend();
-        ThreadStateController.pause(10);
-        thread.checkThreadState(RUNNABLE);
-        checkSuspendedThreadState(thread, RUNNABLE);
-        thread.resume();
+            thread.suspend();
+            ThreadStateController.pause(10);
+            thread.checkThreadState(RUNNABLE);
+            checkSuspendedThreadState(thread, RUNNABLE);
+            thread.resume();
 
-        synchronized (globalLock) {
-            thread.transitionTo(BLOCKED);
-            thread.checkThreadState(BLOCKED);
-            checkLockInfo(thread, BLOCKED,
-                          globalLock, Thread.currentThread());
-        }
+            synchronized (globalLock) {
+                thread.transitionTo(BLOCKED);
+                thread.checkThreadState(BLOCKED);
+                checkLockInfo(thread, BLOCKED,
+                              globalLock, Thread.currentThread());
+            }
 
-        thread.transitionTo(WAITING);
-        thread.checkThreadState(WAITING);
-        checkLockInfo(thread, Thread.State.WAITING,
-                      globalLock, null);
+            thread.transitionTo(WAITING);
+            thread.checkThreadState(WAITING);
+            checkLockInfo(thread, Thread.State.WAITING,
+                          globalLock, null);
 
-        thread.transitionTo(TIMED_WAITING);
-        thread.checkThreadState(TIMED_WAITING);
-        checkLockInfo(thread, TIMED_WAITING,
-                      globalLock, null);
+            thread.transitionTo(TIMED_WAITING);
+            thread.checkThreadState(TIMED_WAITING);
+            checkLockInfo(thread, TIMED_WAITING,
+                          globalLock, null);
 
 
-        thread.transitionToPark(true /* timed park */);
-        thread.checkThreadState(TIMED_WAITING);
-        checkLockInfo(thread, TIMED_WAITING, null, null);
+            thread.transitionToPark(true /* timed park */);
+            thread.checkThreadState(TIMED_WAITING);
+            checkLockInfo(thread, TIMED_WAITING, null, null);
 
-        thread.transitionToPark(false /* indefinite park */);
-        thread.checkThreadState(WAITING);
-        checkLockInfo(thread, WAITING, null, null);
+            thread.transitionToPark(false /* indefinite park */);
+            thread.checkThreadState(WAITING);
+            checkLockInfo(thread, WAITING, null, null);
 
-        thread.transitionToSleep();
-        thread.checkThreadState(TIMED_WAITING);
-        checkLockInfo(thread, TIMED_WAITING, null, null);
-
-        thread.transitionTo(TERMINATED);
-        thread.checkThreadState(TERMINATED);
+            thread.transitionToSleep();
+            thread.checkThreadState(TIMED_WAITING);
+            checkLockInfo(thread, TIMED_WAITING, null, null);
 
-        try {
-            System.out.println(thread.getLog());
-        } catch (InterruptedException e) {
-            e.printStackTrace();
-            System.out.println("TEST FAILED: Unexpected exception.");
-            throw new RuntimeException(e);
+            thread.transitionTo(TERMINATED);
+            thread.checkThreadState(TERMINATED);
+        } finally {
+            try {
+                System.out.println(thread.getLog());
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+                System.out.println("TEST FAILED: Unexpected exception.");
+                throw new RuntimeException(e);
+            }
         }
         System.out.println("Test passed.");
     }