Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top