Solved

service taking long time

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

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
A short article about problems I had with the new location API and permissions in Marshmallow
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

708 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

19 Experts available now in Live!

Get 1:1 Help Now