This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

URLConnection problem  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I'm having a problem using URLConnections that I'm hoping someone can shed some light on. The basic problem is: if a client creates numerous URLConnections very rapidly, eventually it stops being able to open any more connections without waiting a few minutes for a resource (client ports?) to be released.

I've simplified the problem down to a relatively simple test case:

I run Tomcat, and drop a simple HTML file in the root. I then run a small Java program that repeatedly opens a URLConnection to the file, reads it, and releases the connection. I find that on the 3963rd attempt, the connection fails. After that, any more attempts fail for approximately 2 minutes. Then it works again and fails on the 3963rd attempt again. If I run "netstat" in a command prompt right after running the test program, a huge list of connections is displayed. This list seems to clear about the same time the program starts to work again.

I wrote an identical program that uses sockets to connect instead of URLConnections, and it can run indefinitely without ever getting errors. However if I run it right after the URLConnection test has failed, it fails as well.

What I've concluded from these tests is that the URLConnection class does not release some resource (I believe this resource is "client ports" allocated by Windows) for about two minutes. Even calling HttpURLConnection.disconnect() does not release this resource. Sockets seem to use the same resource, but release this resource immediately when close() is called.

Does anyone know of a way to get the URLConnection class to release this resource immediately? Or any workaround other than writing all my HTTP communication from scratch using sockets?

Information about the platform I'm using:
- Windows XP
- Java 1.3.1_08 (also tested with 1.4.2_02 - same behavior)


Here is my test program that uses URLConnections:



And here is my equivalent test program that uses sockets:



Thanks in advance for any help..
Will Ross
www.inmedius.com
[ May 27, 2004: Message edited by: Will Ross ]
 
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tested your code with:

OS: Linux 2.6.5
Webserver: xitami v2.5b5
java: 1.5b and java: 1.4.2

runs fine with 7000 requests for both javas,
and - only tested with 1.5: for 70.000 requests - no pause involved, and memory monitoring showed constant value.
 
Will Ross
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes; I'm pretty sure that this is only a problem with Windows. Although I assume there is some limit to available ports/file descriptors on other OS's also, it might be very high - 64k or something.

I saw a similar discussion here indicating that this is just a Windows issue.


Originally posted by Stefan Wagner:
I tested your code with:

OS: Linux 2.6.5
Webserver: xitami v2.5b5
java: 1.5b and java: 1.4.2

runs fine with 7000 requests for both javas,
and - only tested with 1.5: for 70.000 requests - no pause involved, and memory monitoring showed constant value.

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!