/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6303187
* @summary Test that no locks are held when a monitor attribute is sampled
* or notif delivered.
* @author Eamonn McManus
* @run clean StringMonitorDeadlockTest
* @run build StringMonitorDeadlockTest
* @run main StringMonitorDeadlockTest 1
* @run main StringMonitorDeadlockTest 2
* @run main StringMonitorDeadlockTest 3
* @run main StringMonitorDeadlockTest 4
*/
public class StringMonitorDeadlockTest {
throw new Exception("Arg should be test number");
}
private static abstract class TestCase {
this.description = description;
}
final StringMonitorMBean monitorProxy =
final TestMBean observedProxy =
public void run() {
}
};
public void run() {}
};
final Runnable withinGetAttribute =
monitorProxy.setNotifyDiffer(true);
int getCount = initGetCount;
for (int i = 0; i < 500; i++) { // 500 * 10 = 5 seconds
if (getCount != initGetCount)
break;
}
if (getCount <= initGetCount)
throw new Exception("Test failed: presumable deadlock");
// This won't show up as a deadlock in CTRL-\ or in
// ThreadMXBean.findDeadlockedThreads(), because they don't
// see that thread A is waiting for thread B (B.join()), and
// thread B is waiting for a lock held by thread A
// Now we know the monitor has observed the initial value,
// so if we want to test notify behaviour we can trigger by
// exceeding the threshold.
t.start();
try {
t.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
};
throw new Exception("Test failed: presumable deadlock");
}
}
return description;
}
}
new TestCase("Remove monitored MBean within monitored getAttribute",
}
},
new TestCase("Stop monitor within monitored getAttribute",
monitorProxy.stop();
}
},
new TestCase("Remove monitored MBean within threshold listener",
}
},
new TestCase("Stop monitor within threshold listener",
monitorProxy.stop();
}
},
};
public static interface TestMBean {
public int getGetCount();
}
}
t.start();
try {
t.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
getCount++;
return thing;
}
}
public int getGetCount() {
return getCount;
}
private volatile int getCount;
}
}