public static void main(String[] args) throws Exception { JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://"); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); RMIJRMPServerImplSub impl = new RMIJRMPServerImplSub(); System.out.println("Creating connectorServer"); connectorServer = new RMIConnectorServer(url, null, impl, mbs); System.out.println("Starting connectorServer"); connectorServer.start(); System.out.println("Making client"); RMIConnection cc = impl.newClient(null); System.out.println("Closing client"); cc.close(); if (connectorServer.isActive()) { System.out.println("Stopping connectorServer"); connectorServer.stop(); } if (failure == null) System.out.println("TEST PASSED, no deadlock"); else System.out.println("TEST FAILED"); }
@Override protected void clientClosed(RMIConnection conn) throws IOException { System.out.println("clientClosed, will call connectorServer.stop"); final Exchanger<Void> x = new Exchanger<Void>(); Thread t = new Thread() { public void run() { try { connectorServer.stop(); } catch (Exception e) { fail(e); } } }; t.setName("connectorServer.stop"); t.start(); waitForBlock(t); /* If this thread is synchronized on RMIServerImpl, then * the thread that does connectorServer.stop will acquire * the clientList lock and then block waiting for the RMIServerImpl * lock. Our call to super.clientClosed will then deadlock because * it needs to acquire the clientList lock. */ System.out.println("calling super.clientClosed"); System.out.flush(); super.clientClosed(conn); }
@Override protected RMIConnection makeClient(String id, Subject subject) throws IOException { RMIConnectionImpl conn = (RMIConnectionImpl) super.makeClient(id, subject); connections.add(conn); return conn; }
public RMIConnection makeClient() throws IOException { return super.makeClient("connection id", null); }