Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

service taking long time

Posted on 2013-11-13
1
Medium Priority
?
433 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 35

Accepted Solution

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

Sara
0

Featured Post

Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
This video teaches viewers about errors in exception handling.
Starting up a Project
Suggested Courses

722 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