JMX连接超时

时间:2013-08-28 20:59:49

标签: java multithreading threadpool jmx

我的线程池正在变满,因为大多数线程都在等待套接字连接。如何为jmx connect添加超时

java.lang.Thread.State: RUNNABLE
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
    - locked <0x05671ad0> (a java.net.SocksSocketImpl)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
    at java.net.Socket.connect(Socket.java:519)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:548)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.<init>(SSLSocketImpl.java:351)
    at com.sun.net.ssl.internal.ssl.SSLSocketFactoryImpl.createSocket(SSLSocketFactoryImpl.java:71)
    at javax.rmi.ssl.SslRMIClientSocketFactory.createSocket(SslRMIClientSocketFactory.java:105)
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:595)
    at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:198)
    at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184)
    at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:322)
    at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
    at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:97)
    at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:185)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1871)
    at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1841)
    at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:257)

2 个答案:

答案 0 :(得分:0)

这是一个艰难的。这取决于您所处的环境,哪个部分超时。

由于防火墙问题或其套接字仍然响起的应用程序崩溃,很可能您在TCP级别遇到连接超时。

JVM的整体connecttimeout设置为-1,默认为无限。你好线程漏洞。

sun.net.client.defaultConnectTimeout (default: -1)

您可以在此处找到Java oracle网络参数的文档:https://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.html

jmx / rmi特定文档遗憾地没有该级别的连接超时设置。但是他们在读取超时时有一堆其他控件:https://docs.oracle.com/javase/8/docs/technotes/guides/rmi/sunrmiproperties.html

您可以使用netcat进行开发,并使用netcat将应用程序指向localhost端口,从而对此进行测试:

# creat socket on port 3333
netcat -l 3333
# now point your app on the socket
# and you should be able to reproduce

这将刺激端口上的死应用或防火墙阻止。

答案 1 :(得分:-2)

只需添加以下系统属性 - “-Dsun.rmi.transport.tcp.responseTimeout = 60000”