Skip to content

Commit

Permalink
8188784: javax/management/notification/BroadcasterSupportDeadlockTest…
Browse files Browse the repository at this point in the history
….java - TEST FAILED: deadlock
  • Loading branch information
kevinjwalls committed Apr 9, 2024
1 parent 6439375 commit 5237f1d
Showing 1 changed file with 18 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2024, 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
Expand Down Expand Up @@ -38,13 +38,8 @@
import javax.management.*;

public class BroadcasterSupportDeadlockTest {

public static void main(String[] args) throws Exception {
try {
Class.forName(ManagementFactory.class.getName());
} catch (Throwable t) {
System.out.println("TEST CANNOT RUN: needs JDK 5 at least");
return;
}

final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
final BroadcasterMBean mbean = new Broadcaster();
Expand Down Expand Up @@ -85,8 +80,9 @@ public void run() {
interested in. */
semaphore.acquire();
Thread.sleep(100);
while (t1.getState() != Thread.State.WAITING)
Thread.sleep(1);
while (t1.getState() != Thread.State.WAITING) {
Thread.sleep(100);
}

// Thread 2 - try to add a listener
final NotificationListener listener = new NotificationListener() {
Expand All @@ -105,31 +101,25 @@ public void run() {
t2.setDaemon(true);
t2.start();

/* Wait for Thread 2 to be blocked on the monitor or to
succeed. */
/* Wait for Thread 2 to be blocked on the monitor or to succeed. */
Thread.sleep(100);

for (int i = 0; i < 1000/*ms*/; i++) {
t2.join(1/*ms*/);
switch (t2.getState()) {
case TERMINATED:
for (int i = 0; i < 1000; i++) {
t2.join(100 /*ms*/);
if (t2.getState() == Thread.State.TERMINATED) {
System.out.println("TEST PASSED");
return;
case BLOCKED:
java.util.Map<Thread,StackTraceElement[]> traces =
Thread.getAllStackTraces();
showStackTrace("Thread 1", traces.get(t1));
showStackTrace("Thread 2", traces.get(t2));
System.out.println("TEST FAILED: deadlock");
System.exit(1);
break;
default:
break;
}
}

System.out.println("TEST FAILED BUT DID NOT NOTICE DEADLOCK");
Thread.sleep(10000);
if (t2.getState() == Thread.State.BLOCKED) {
System.out.println("TEST FAILED: deadlock");
} else {
System.out.println("TEST FAILED BUT DID NOT NOTICE DEADLOCK (state = " + t2.getState() + ")");
}
java.util.Map<Thread,StackTraceElement[]> traces = Thread.getAllStackTraces();
showStackTrace("Thread 1", traces.get(t1));
showStackTrace("Thread 2", traces.get(t2));
System.exit(1);
}

Expand All @@ -152,6 +142,7 @@ public static interface BroadcasterMBean {
public static class Broadcaster
extends NotificationBroadcasterSupport
implements BroadcasterMBean {

public synchronized void block(Semaphore semaphore) {
Object lock = new Object();
synchronized (lock) {
Expand Down

0 comments on commit 5237f1d

Please sign in to comment.