3

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

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)
4

2 回答 2

0

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

很可能您在 TCP 级别遇到连接超时,原因可能是防火墙问题或其套接字仍处于打开状态的死应用程序。

JVM 的整体连接超时设置为 -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 并将您的应用程序指向 localhost 端口:

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

这将刺激端口上的死应用程序或防火墙块。

于 2017-12-12T00:06:00.677 回答
-1

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

于 2016-08-24T12:43:14.067 回答