有关 java.net.URLConnection 超时的帮助吗?
连接超时,并且该连接的开发人员处于其想法列表的底部。
日志有一个友好的:
[6/24/10 6:32:34:032 EDT] 0000000d ThreadMonitor W WSVR0605W: Thread "WebContainer : 136" (0000c53e) has been active for 719542 milliseconds and may be hung. There is/are 45 thread(s) in total in the server that may be hung.
代码看起来像:
try {
final URLConnection connection = url.openConnection();
connection.setConnectTimeout(CONNECT_TIME_SECONDS * 1000);
connection.setReadTimeout(READ_TIME_SECONDS * 1000);
is = connection.getInputStream();
document = builder.parse(is);
} catch (SAXException e) {
log.error(e);
throw new PageContentException(e);
} finally {
if (is != null) {
is.close();
}
}
我最好的猜测是 url.openConnection() 正在尝试在连接超时降低到合理的水平之前打开连接,但是 什么都没有 //java.sun.com/j2se/1.5.0/docs/api/java/net/URL.html" rel="nofollow noreferrer">API 向我展示了如何以不同的方式做到这一点。
关于尝试什么的建议?
A Connection is timing out, and the developer on it is at the bottom of his list of ideas.
The logs have a friendly:
[6/24/10 6:32:34:032 EDT] 0000000d ThreadMonitor W WSVR0605W: Thread "WebContainer : 136" (0000c53e) has been active for 719542 milliseconds and may be hung. There is/are 45 thread(s) in total in the server that may be hung.
And the code looks like:
try {
final URLConnection connection = url.openConnection();
connection.setConnectTimeout(CONNECT_TIME_SECONDS * 1000);
connection.setReadTimeout(READ_TIME_SECONDS * 1000);
is = connection.getInputStream();
document = builder.parse(is);
} catch (SAXException e) {
log.error(e);
throw new PageContentException(e);
} finally {
if (is != null) {
is.close();
}
}
My best guess is that url.openConnection() is attempting to open the connection before the connect timeout was lowered to something reasonable, but nothing in the API shows me how I'd do that differently.
Suggestions on what to try?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我会获取线程转储并查看它到底卡在哪里。不要假设。然后你就可以明白为什么它卡在那里了。如果您已经有线程转储,请发布堆栈跟踪。
I'd get the thread dump and see where exactly it's stuck. Don't assume. Then you can see why it's stuck there. If you already have the thread dump, please post the stack trace.
我认为这就是可能的情况。在尝试连接开始后设置连接超时不太可能起作用,IMO。
您是否尝试过在系统属性中设置“sun.net.client.defaultConnectTimeout”属性? 此处记录了它。
I think this is the likely scenario. Setting the connection timeout after attempt to connect has started is unlikely to work, IMO.
Have you tried setting the "sun.net.client.defaultConnectTimeout" property in the system properties? It is documented here.
不。如果是这样的话 URLConnection.setConnectionTimeout() 将完全没有意义,因为没有办法比你更早地调用它。
No. If that was the case URLConnection.setConnectionTimeout() would be completely pointless, as there is no way to call it earlier than you are.
也许是因为“最终”。我不确定你为什么要放在那里,但我认为删除 Final 应该有所帮助。
it maybe because of "final". I'm not sure why you are putting in there, but I think removing final should help.