--- a/jdk/test/javax/management/standardmbean/DeadlockTest.java Sat Dec 13 20:22:21 2014 +0000
+++ b/jdk/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.");
}