Solved

service taking long time

Posted on 2013-11-13
1
431 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

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.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

759 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