Solved

service taking long time

Posted on 2013-11-13
1
432 Views
Last Modified: 2013-11-13
Hi,
 I am calling a service through  the following code :
obj = new URL(url)
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
BufferedReader in = new BufferedReader(
                    new InputStreamReader(con.getInputStream()));

Here what i did is i gave a wrong url which takes some time to error out.
Finding that in such a case of a wrong url my code will be unneccesarrily stuck.

I added the following :
con.setReadTimeout(60*1000);
Before the con.getInputStream() line

Now when i was checking on my local machine the con.getInputStream() line
threw an exception if taking more than a minute.

But when i deployed the code on a remote linux machine
The con.getInputStream() line took more than 3 minutes to error out.

Even though i have specified the timout of 1 minute. I am unable to understand why on remote machine its taking long time and why on my local machine the same code is behaving differently.

If i type the url directly on my browser it takes 20 seconds to error out showing :
The connection has timed out...

Please help

Thanks & Regards
Robin
0
Comment
Question by:Rohit Bajaj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 34

Accepted Solution

by:
sarabande earned 500 total points
ID: 39645348
didn't you need a connection timeout rather than a read timeout?

Sara
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question