9 Replies Latest reply: Jul 2, 2012 2:24 AM by EJP RSS

    How to detect a JMX lost connection

    843793
      I've got a situation where a client is talking to a server via a JMX connection.The server will be performing a time consuming, resource hungry transaction that may take and so may take a long to return. During this time it's possible that the client is terminated and/or the connection is dropped.

      Is there a way for the JVM on the client to detect that the port has closed? I'd like to use this callback to terminate the server transaction and free up resources/CPU for other transactions.

      Cheers.
        • 1. Re: How to detect a JMX lost connection
          843793
          Any ideas any body?
          • 2. Re: How to detect a JMX lost connection
            843793
            Guess not :-(
            • 3. Re: How to detect a JMX lost connection
              EJP
              During this time it's possible that the client is terminated and/or the connection is dropped.
              The connection will only be dropped if either the client or the server is terminated or an intermediate firewall times it out.
              Is there a way for the JVM on the client to detect that the port has closed?
              No, because the port won't have closed. The connection may have been dropped; that's not the same thing. RMI does use TCP keep-alive, which can detect a broken connection but only after two hours.
              • 4. Re: How to detect a JMX lost connection
                843793
                Hi ejp,

                Thanks for getting back to me - it's much appreciated.

                I'm trying to find some mechanism for the server detecting that the client has gone away. I was hoping that closing the socket might have been the answer, but it looks as if that isn't the case. In that case is it possible that:

                1) I can configure the RMI keep-alive for a much lower value (a couple of minutes would be acceptable)
                2) Is there some other mechanism I could use to detect the client is no longer available?

                I've tried using an interface to call the client, but unfortunately that doesn't work - every thing just locked up!

                Thank
                • 5. Re: How to detect a JMX lost connection
                  EJP
                  1) I can configure the RMI keep-alive for a much lower value (a couple of minutes would be acceptable)
                  There isn't an RMI keep-alive. There is a TCP keep-alive. You can't configure it from Java.
                  2) Is there some other mechanism I could use to detect the client is no longer available?
                  No.
                  • 6. Re: How to detect a JMX lost connection
                    843793
                    OK, I guess it's back to the drawing board.

                    Thanks for your help.
                    • 7. Re: How to detect a JMX lost connection
                      jtahlborn
                      make the initial operation asynchronous. client calls a "start operation" method (which returns immediately), then periodically calls a "check for result" method which hangs for a bit then returns null if no result yet or the result if the operation is finished. if the client stops calling the "check for result" method (within some time window), then the server knows the client is dead.
                      • 8. Re: How to detect a JMX lost connection
                        615811
                        I too have a similar requirement. How will the server know that the client has terminated abruptly.

                        I have JMX client and MbeanServer on weblogic, which communicates as required. Gets the ip of the client and displays the process running on that client.
                        notification listener also works.

                        The problem I have is, if the client is terminated, it does not get reflected on the server. The server shows that client still listed, if it is stopped abruptly, when that process running has not completed and the mbean is not unregistered.

                        How can I get to know that the jmx client has terminated and unregister it from the server list.

                        Thanks.
                        • 9. Re: How to detect a JMX lost connection
                          EJP
                          The answer to your question was posted immediately above, in December 2009. Please read the thread before you revive it unnecessarily. Locking.