changeset 10340:e3690e960bef

8067241: DeadlockTest.java failed with negative timeout value Reviewed-by: dfuchs, sspitsyn
author sjiang
date Mon, 15 Dec 2014 19:21:59 +0100
parents 85d578d8a841
children 29801793a0b0
files test/javax/management/standardmbean/DeadlockTest.java
diffstat 1 files changed, 6 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/test/javax/management/standardmbean/DeadlockTest.java	Thu Dec 04 10:34:55 2014 +0100
+++ b/test/javax/management/standardmbean/DeadlockTest.java	Mon Dec 15 19:21:59 2014 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2014, 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
@@ -24,7 +24,7 @@
 /*
  * @test
  * @bug 6331746
- * @summary Deadlock on synchronization problem
+ * @summary Test a deadlock and will be blocked forever if the deadlock is present.
  * @author Shanliang JIANG
  * @run main DeadlockTest
  */
@@ -55,43 +55,25 @@
         BadBoy bb = new BadBoy(dt);
         bb.start();
 
-        final long timeout = 2000;
-        long stopTime = System.currentTimeMillis() + timeout;
-        long timeToWait = timeout;
         synchronized(bb) {
-            while(!bb.gotLock || timeToWait > 0) {
-                bb.wait(timeToWait);
-
-                timeToWait = stopTime - System.currentTimeMillis();
+            while(!bb.gotLock) {
+                bb.wait(); // if blocked here, means failing to get lock, impossible.
             }
         }
 
-        if (!bb.gotLock) {
-            throw new RuntimeException("Failed to get lock, impossible!");
-        }
-
         System.out.println("main: The BadBay is holding the lock forever.");
 
         System.out.println("main: Create a WorkingBoy to see blocking ...");
         WorkingBoy wb = new WorkingBoy(dt);
 
-        stopTime = System.currentTimeMillis() + timeout;
-        timeToWait = timeout;
-
         synchronized(wb) {
             wb.start();
 
-            while(!wb.done || timeToWait > 0) {
-                wb.wait(timeToWait);
-
-                timeToWait = stopTime - System.currentTimeMillis();
+            while(!wb.done) {
+                wb.wait(); // if blocked here, the deadlock happends
             }
         }
 
-        if (!wb.done) {
-            throw new RuntimeException("It is blocked!");
-        }
-
         System.out.println("main: OK, bye bye.");
     }