synchronized (dispatcher) { synchronized (this) { try { System.out.println("disconnecting from remote peer!"); setState(ConnectionState.CLOSED);
synchronized (this) { try { System.out.println("disconnecting from remote peer!"); setState(ConnectionState.CLOSED);
    void disconnect() {        /* To allow this method to be called without risk of deadlock from synchronized methods in the dispatcher,        * we must acquire the lock on the dispatcher before locking on this object.               */        synchronized (dispatcher) {            synchronized (this) {                try {                    System.out.println("disconnecting from remote peer!");                    setState(ConnectionState.CLOSED);                    if (dispatcher != null) {                        dispatcher.close();                    }                    if (sender != null) {                        sender.close();                    }                    sender = null;                    if (socket != null) {                        socket.close();                    }                    socket = null;                } catch (IOException e) {                    System.out.println("Caught an IOException disconnecting " +                        e);                }                if (connectionListener != null) {                    connectionListener.connectionClosed(this);                }            }        }    }