15

I'm trying to set request timeout for JMX Connector but seems like it doesn't work.

env.put("jmx.remote.x.request.waiting.timeout", new Long(30000));

But since it didn't work, i googled to see the reason and found out that in standard JMX remote api doesn't support the above environment variable.

Is there any other way to set the request time-out?

Ami
  • 4,241
  • 6
  • 41
  • 75
sasankad
  • 3,543
  • 3
  • 24
  • 31
  • could you add the timeout to the JMX connection upon creation e.g. JMXConnector jmxc = connectWithTimeout(jmxServiceURL, 30, TimeUnit.SECONDS); – Sean F Oct 09 '12 at 00:23
  • @SeanF, Yeah i went through that blog as well, but my requirement is to set the request timeout not the connection time out. I was wondering whether JMXMP connector have that capability. – sasankad Oct 09 '12 at 00:42
  • oh ok, sorry cant help you there. – Sean F Oct 09 '12 at 01:48

2 Answers2

9

If you use default JMX protocol - the RMI - then the best option for the client side timeout is the global RMI connection timeout. Of course it will work only if you do not need to use RMI connections that have to be open forever.

Here is sample property for the timeouts (taken from Oracle RMI documentation: http://docs.oracle.com/javase/7/docs/technotes/guides/rmi/sunrmiproperties.html):

-Dsun.rmi.transport.tcp.responseTimeout=60000

I have tested it, it really works. In the oracle documentation there are also few other useful properties for client and server side of the communication.

bartosz.r
  • 454
  • 4
  • 10
  • If we're talking about something like a junit test, you could also do this programatically prior to starting jmx, eg in a @BeforeClass method: System.setProperty("sun.rmi.transport.tcp.responseTimeout", "60000") – fuzzyBSc Feb 02 '18 at 03:50
3

u can try these codes to set the JMX connector timeout:

   JMXConnector connectWithTimeout(JMXServiceURL url, long timeout, TimeUnit unit) {
    ExecutorService executor = Executors.newSingleThreadExecutor();
       Future<JMXConnector> future = executor.submit(new Callable<JMXConnector>() {
            public JMXConnector call() {
                return JMXConnectorFactory.connect(url);
            }
              });
       return future.get(timeout, unit);
          }
  • This is the solution i adapted as well. But i forgot to update my answer. So i'll accept this answer. – sasankad Sep 15 '13 at 23:44
  • 11
    Ok, but this doesn't actually cause hanged connections to time out. It just causes the thread to stop waiting on the connection and assume failure. In a high traffic environment, connections left behind in this manner will quickly gobble things up. – Mihai Danila Sep 20 '13 at 15:17