/*
* 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.
*/
/*
* @summary SynchronizerDeadlock creates threads that are deadlocked
* waiting for JSR-166 synchronizers.
* @author Mandy Chung
* @build Barrier
*/
public class SynchronizerDeadlock {
private Lock a = new ReentrantLock();
private Lock b = new ReentrantLock();
private Lock c = new ReentrantLock();
public SynchronizerDeadlock() {
// make them daemon threads so that the test will exit
for (int i = 0; i < EXPECTED_THREADS; i++) {
}
}
void goDeadlock() {
// Wait until all threads have started
// reset for later signals
synchronized(this) {
try {
wait(100);
} catch (InterruptedException e) {
// ignore
}
}
}
// sleep a little so that all threads are blocked before notified.
try {
} catch (InterruptedException e) {
// ignore
}
}
void waitUntilDeadlock() {
for (int i=0; i < 100; i++) {
// sleep a little while to wait until threads are blocked.
try {
} catch (InterruptedException e) {
// ignore
}
boolean retry = false;
retry = true;
break;
}
}
if (!retry) {
break;
}
}
}
super(name);
}
public void run() {
f();
}
private void f() {
try {
g();
} finally {
}
}
private void g() {
throw new RuntimeException("should not reach here.");
}
}
throw new RuntimeException("Expected to have " +
EXPECTED_THREADS + " to be in the deadlock list");
}
boolean[] found = new boolean[EXPECTED_THREADS];
found[j] = true;
}
}
}
boolean ok = true;
}
if (!ok) {
}
}
throw new RuntimeException("Unexpected result returned " +
" by findMonitorDeadlockedThreads method.");
}
}
}