• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connection Timeout in URLConnection

 
vivek dhiman
Ranch Hand
Posts: 152
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have the java code which hit the web service and get the data.



But sometime this works and sometimes gives connectionTimeout exception.


Any Suggestions
 
Luan Cestari
Ranch Hand
Posts: 163
C++ Redhat Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably the fault is not the client (your code), but the server ( web service). This error means that the URL waited the specified time but didn't get any reponse so it automatically closed the connection.
 
vivek dhiman
Ranch Hand
Posts: 152
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.

But Sometimes it connect and sometime not. Like first time if I hit its give me data when i hit second time its gives me connection timeout.Sometimes it works for 8-9 times & then connection timeout further.That is really strange for me. If this is the target server issue, then how can i debug this.

 
Luan Cestari
Ranch Hand
Posts: 163
C++ Redhat Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically, if the problem is the server side which can't accept new connection, so if you try "telnet www.google.com 80" you will get the same problem. In other words, the server side handles to accept the connection (using a pool of threads with a listener or NIO, but the details doesn't matter) but it is too busy (all the working threads are busy to handle other connections). We can create an analogy like when you call someone phone that is already in a call. That person can be aware of the call, but he is already answering someone, so he need to finish the old call to handle the new one. If you doesn't want to wait enough (timeout parameter) you will end the call.

You can use others tools to simulate this issue creating stress tests. You can use JMeter (or SoapUI or other tool) to simulate 20 (or more) connections at the same time and see if the server side is able to answer them.
 
vivek dhiman
Ranch Hand
Posts: 152
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, If i am trying telnet www.google.com 80 its giving me an error Connect Failed. So what you suggest, As server from where we getting the url is of other party and we cant check on our end, we have only url.

Thanks
 
Paul Clapham
Sheriff
Pie
Posts: 20719
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You seem to find it surprising that it sometimes takes more than 20 seconds to connect to that URL. Is that surprise based on actual experience with the web service? Those of us trying to answer your question don't have any experience with it, so it's quite possible that it has that sort of slow response time. In other words, don't ask us whether a response time of over 20 seconds is unexpected because we have no way of knowing.
 
vivek dhiman
Ranch Hand
Posts: 152
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. Thanks. Idea behind this I got
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic