-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Tim,

On 5/16/2011 4:06 AM, Tim Stibbs wrote:
> I have a java client that is making a large number of calls to a servlet
> running in a web app in tomcat 5.5.28. I have noticed that if the client
> process runs for too long, the client machine runs out of ports throwing a
> "java.net.BindException: Address already in use: connect". I thought that
> java's URLConnection maintained an internal pool of connections, and that so
> long as keep alive was enabled it would re-use the connections.

The Javadoc for java.net.URL has this to say about the openConnection
method:

"A new connection is opened every time by calling the openConnection
method of the protocol handler for this URL."

That seems to be conflicting with this other documentation:

http://download.oracle.com/javase/1.5.0/docs/guide/net/http-keepalive.html

... which says that keep-alive is transparent. I don't see you setting a
"Connection: keep-alive" header, which you probably should be doing. The
example code in the above document does /not/ explicitly set this
header, but it couldn't hurt.

You should also check this out:
http://forums.java.net/node/656951

Evidently, not properly reading the server's response could be a
problem, too. Note that HttpURLConnection requires that you monitor two
separate streams for responses: the output and error streams. You should
drain one or the other stream based upon the response code you get from
the server.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk3RTe0ACgkQ9CaO5/Lv0PBvrQCcDwOPEO/GZtHAHSuUf1FO23M/
Vh4AoKvSDDZWe6hjtAlHnENWG1ixbdAf
=QG3e
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to