Solved

service taking long time

Posted on 2013-11-13
1
429 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
1 Comment
 
LVL 33

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: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Support for Notepad++ (including downloading & installing a plugin) 5 115
Windows 10 IE Certificate Issue 10 45
servlet example 11 40
ejb on wildfly 5 19
This is about my first experience with programming Arduino.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

813 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now