views:

2623

answers:

4

I have a Java application which uses a third-party COM component through a Java-COM bridge. This COM component opens a socket connection to a remote host.

This host can take some time to respond, and I suspicious that I'm getting a timeout. I'm not sure because as I said, it's a closed-source third-party component.

The API of this component does not expose the socket connection to me, so I have no way to configure the timeout. So I wonder if there is any way to tweak the system default timeout.

I'm using a Windows Server 2008 x64 Enterprise Edition.

A: 

You can introduce your own SocketImplFactory (See static method setSocketImpl() of java.net.Socket class). Then you can create SocketImpl objects with your own value of SO_TIMEOUT parameter.

Matej
The socket is not being created by java code, but by a COM object, in C++ I guess.
tuler
Ah, yes. You are right. Well, I am wondering if something similar is not possible also with native windows libraries.
Matej
A: 

The registry settings described in "Windows Vista Tcp Ip Configuration Settings" at Microsoft for TcpMaxDataRetransmissions may allow you to set the global timeouts you need.

You will, of course, need to be careful that you do not cripple the remainder of the server in the process with delayed responses to real errors.

Pekka
+1  A: 

Do you want to build your application so that it knows at runtime whether or not a timeout happened, or do you want to inspect the behavior of the closed-source COM component? If it's the latter, install Wireshark on your dev box and watch the connection. If it's the former, do you want to ensure that your Java call out to native land doesn't hang forever? If that's the case, look into the java.util.concurrent executor service stuff -- there's a way to call a method in another thread and wait a maximum of N seconds before returning control to your thread.

ShabbyDoo
A: 

If you'd like to see the connection establish, and then perhaps drop from timeout, you can use TCPview: http://technet.microsoft.com/en-us/sysinternals/bb897437.aspx

Mathew