/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* @test
* @bug 6697180
* @summary test on a client notification deadlock.
* @author Shanliang JIANG
* @run clean MultiThreadDeadLockTest
* @run build MultiThreadDeadLockTest
* @run main MultiThreadDeadLockTest
*/
public class MultiThreadDeadLockTest {
print("Create the MBean server");
print("Initialize environment map");
print("Specify a client socket factory to control socket creation.");
print("Specify a server idle timeout to make a server close an idle connection.");
print("Disable client heartbeat.");
print("Create an RMI server");
print("Add listener to toto MBean");
print("send notif, listener will block the fetcher");
", the sever should close the idle connection.");
print("start the user thread to call mbean method, it will get IOexception" +
" and start the reconnection, the socket factory will block the" +
" socket creation.");
print("Free the listener, the fetcher will get IO and makes " +
"a deadlock if the bug is not fixed.");
print("Allow to create new socket for the reconnection");
print("Check whether the user thread gets free to call the mbean.");
throw new RuntimeException("Possible deadlock!");
}
print("Remove the listener.");
print("\nWell passed, bye!");
}
public UserThread() {
setDaemon(true);
}
public void run() {
try {
} catch (Exception e) {
throw new Error(e);
}
synchronized(UserThread.class) {
done = true;
UserThread.class.notify();
}
}
synchronized(UserThread.class) {
if(!done) {
try {
} catch (Exception e) {
throw new Error(e);
}
}
}
return done;
}
private boolean done = false;
}
public static interface TotoMBean {
public void allowReturn();
}
implements TotoMBean {
public void allowReturn() {
enter("allowReturn");
leave("allowReturn");
}
public void sendNotif() {
enter("sendNotif");
leave("sendNotif");
}
}
enter("handleNotification");
leave("handleNotification");
}
};
public static class RMIClientFactory
implements RMIClientSocketFactory, Serializable {
enter("createSocket");
//print("Calling createSocket(" + host + " " + port + ")");
leave("createSocket");
return s;
}
}
public static class StateMachine {
public static void waitState(int s) {
synchronized (lock) {
while (state != s) {
try {
} catch (InterruptedException ire) {
// should not
}
}
}
}
public static int getState() {
synchronized (lock) {
return state;
}
}
public static void setState(int s) {
synchronized (lock) {
state = s;
}
}
}
}
}
}
}