我有一个 Java 应用程序,它通过 Java-COM 桥使用第三方 COM 组件。
该 COM 组件打开到远程主机的套接字连接。
该主机可能需要一些时间才能响应,我怀疑我超时了。 我不确定,因为正如我所说,它是一个闭源第三方组件。
该组件的API没有向我公开套接字连接,因此我无法配置超时。 所以我想知道是否有任何方法可以调整系统默认超时。
我使用的是 Windows Server 2008 x64 企业版。
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.
发布评论
评论(4)
您是否想要构建应用程序以便在运行时知道是否发生超时,或者是否想要检查闭源 COM 组件的行为? 如果是后者,请在您的开发盒上安装 Wireshark 并观察连接。 如果是前者,您是否想确保 Java 对本地的调用不会永远挂起? 如果是这种情况,请查看 java.util.concurrent executor 服务内容——有一种方法可以调用另一个线程中的方法,并在将控制权返回给线程之前等待最多 N 秒。
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.
如果您想查看连接建立,然后可能因超时而断开,您可以使用 TCPview:http://technet.microsoft.com/en-us/sysinternals/bb897437.aspx
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
您可以引入自己的SocketImplFactory(参见静态方法setSocketImpl())。 然后您可以使用您自己的 SO_TIMEOUT 参数值创建 SocketImpl 对象。
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.
Microsoft 的“Windows Vista Tcp Ip 配置设置”中描述的用于 TcpMaxDataRetransmissions 的注册表设置可能允许您设置所需的全局超时。
当然,您需要小心,不要因为对实际错误的延迟响应而导致该过程中服务器的其余部分瘫痪。
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.