有关 java.net.URLConnection 超时的帮助吗?

发布于 2024-09-06 17:28:51 字数 1143 浏览 8 评论 0原文

连接超时,并且该连接的开发人员处于其想法列表的底部。

日志有一个友好的:

[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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

最终幸福 2024-09-13 17:28:51

我会获取线程转储并查看它到底卡在哪里。不要假设。然后你就可以明白为什么它卡在那里了。如果您已经有线程转储,请发布堆栈跟踪。

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.

℉服软 2024-09-13 17:28:51

我最好的猜测是 url.openConnection() 尝试在连接超时降低到合理值之前打开连接,但 API 中没有任何内容向我展示如何以不同的方式执行此操作。

我认为这就是可能的情况。在尝试连接开始后设置连接超时不太可能起作用,IMO。

关于尝试什么的建议?

您是否尝试过在系统属性中设置“sun.net.client.defaultConnectTimeout”属性? 此处记录了它。

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.

I think this is the likely scenario. Setting the connection timeout after attempt to connect has started is unlikely to work, IMO.

Suggestions on what to try?

Have you tried setting the "sun.net.client.defaultConnectTimeout" property in the system properties? It is documented here.

陈独秀 2024-09-13 17:28:51

我最好的猜测是
url.openConnection() 正在尝试
在连接之前打开连接
超时被降低到某个值
合理。

不。如果是这样的话 URLConnection.setConnectionTimeout() 将完全没有意义,因为没有办法比你更早地调用它。

My best guess is that
url.openConnection() is attempting to
open the connection before the connect
timeout was lowered to something
reasonable.

No. If that was the case URLConnection.setConnectionTimeout() would be completely pointless, as there is no way to call it earlier than you are.

橘亓 2024-09-13 17:28:51

也许是因为“最终”。我不确定你为什么要放在那里,但我认为删除 Final 应该有所帮助。

it maybe because of "final". I'm not sure why you are putting in there, but I think removing final should help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文