3

My Thread pool is becoming full because, most of the threads are waiting for the socket connection. How to add timeout for 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)
Sangeeth
  • 614
  • 1
  • 5
  • 14
  • Isn't it duplicate of http://stackoverflow.com/questions/12791025/how-to-set-request-timeout-for-jmx-connector/. The difference may be in connect vs response timeout, but otherwise it is the same. – bartosz.r Dec 18 '13 at 11:48
  • please add the relevant part of code, so that I could look into a solution. – RRM Apr 17 '15 at 16:38
  • @bartosz.r it isn't the same, see my answer below. Read time-out is configurable for rmi/jmx. Connect timeout for TCP is not, you need to go deeper in the network config of java to do that unfortunately. – drewboswell Dec 12 '17 at 00:19

2 Answers2

0

This is a tough one. It depends on which part is timing out due to the environment you are in.

Most probably you are encountering a connect timeout at the TCP level due either firewall issues or a dead application with its socket still up.

The overall connecttimeout for the JVM is set to -1, so infinite by default. Hello thread leaks.

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

You can find the documentation for Java oracle network parameters here: https://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.html

The jmx/rmi specific documentation sadly doesn't have a connect timeout setting at that level. But they have a bunch of other controls on the read time-out: https://docs.oracle.com/javase/8/docs/technotes/guides/rmi/sunrmiproperties.html

You can test this while developing with something as simple as using netcat and pointing your app over to the localhost port:

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

This will stimulate a dead app or firewall block on the port.

drewboswell
  • 150
  • 6
-1

Just add the Following System property - "-Dsun.rmi.transport.tcp.responseTimeout=60000"

  • Why has this answer been downvoted? See this [answer](https://stackoverflow.com/questions/12791025/how-to-set-request-timeout-for-jmx-connector) – Lonzak Nov 04 '20 at 08:44