如何为JMX Connector设置请求超时

我正在尝试为JMX Connector设置请求超时,但似乎它不起作用。

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

但由于它不起作用,我用谷歌搜索原因并发现在标准的JMX远程api中不支持上述环境变量。

有没有其他方法来设置请求超时?

如果使用默认的JMX协议 – RMI – 那么客户端超时的最佳选择是全局RMI连接超时。 当然,只有当您不需要使用必须永久打开的RMI连接时,它才会起作用。

以下是超时的示例属性(取自Oracle RMI文档: http : //docs.oracle.com/javase/7/docs/technotes/guides/rmi/sunrmiproperties.html ):

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

我测试了它,它确实有效。 在oracle文档中,通信的客户端和服务器端也很少有其他有用的属性。

你可以尝试这些代码来设置JMX连接器超时:

  JMXConnector connectWithTimeout(JMXServiceURL url, long timeout, TimeUnit unit) { ExecutorService executor = Executors.newSingleThreadExecutor(); Future future = executor.submit(new Callable() { public JMXConnector call() { return JMXConnectorFactory.connect(url); } }); return future.get(timeout, unit); }