Ryan Jaw

Greenhorn
+ Follow
since Nov 04, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ryan Jaw

Just to follow up, I now have things working well.
I ended up ditching URLConnection and instead use HTTPClient, which support timeouts:
http://www.innovation.ch/java/HTTPClient/urlcon_vs_httpclient.html
� � � �setTimeout(int�time)
� � � � ���������Sets the timeout to be used for creating connections and reading responses.
Apparently you can also set timeouts as follows (or if you prefer, using System.setProperty in your code):
java -Dsun.net.client.defaultConnectTimeout=30000 -Dsun.net.client.defaultReadTimeout=30000
if these are exceeded, an exception will be thrown, allowing you to wait until later to try again.
I was satisfied with HTTPClient though, so I never tried the latter.
20 years ago
Ah, I see. I did not know that. Thanks a bunch!
PS- see if you can find any query that will return an explanation of this from google ... I pulled my hair out
20 years ago
Hi all,
Sorry in advance for such a dumb question ...
I have the condition where I check to see if my HttpURLConnection response code is okay:
if (code != HttpURLConnection.HTTP_OK)
{
String message = httpConnection.getResponseMessage();
System.out.println(code + " " + message);
return;
}
Suppose that my condition here is met, and the code + message is printed. I'm confused about what 'return;' does. I know this must sound stupid, but I have no idea what purpose it serves
Thanks!
20 years ago
oh yes, and it is a new URLConnection each time
20 years ago
Thanks,
Someone on experts-change.com (I've been spreading my love around :-) suggested:
-------
You could cast the URLConnection to HttpURLConnection and only proceed with getting a stream if HTTP_OK:
http://java.sun.com/j2se/1.4.2/docs/api/java/net/HttpURLConnection.html#HTTP_OK
-------
What the heck, it's worth a try ...
I've inserted the following into my code prior to "while ( (s=in.readLine()) != null)":
����� ��������� � � �HttpURLConnection httpConnection = (HttpURLConnection)conn;
����� ��������� � � �int code = httpConnection.getResponseCode();
����� ��������� � � �if (code != HttpURLConnection.HTTP_OK)
����� ��������� � � �{
����� ��������� � � � � String message = httpConnection.getResponseMessage();
����� ��������� � � � � System.out.println(code + " " + message);
����� ��������� � � � � return;
����� ��������� � � �} else {
����� ��������� � � � �����System.out.println("HTTP_OK: "+code);
����� ��������� � � �}
It's nothing but informative at this point, but will let me know what the response code is the next time the 'hang' happens. �Stay tuned, will probably take several hours for it to re-occur.
20 years ago
What operating system?
Try checking your PATH environment variable.
20 years ago
Hi all,
I'm new to these forums - hope someone can help me.
I have a java application that reads in the contents of a URL every 10 minutes. Basically:
...
BufferedReader in = new BufferedReader( new InputStreamReader(conn.getInputStream()));
String s=null;
while ( (s=in.readLine()) != null) {
//do something
...
Everything works fine, until (at random intervals), my app just hangs at
while ( (s=in.readLine()) != null)
When it 'hangs' it doesn't use any cpu time ... just sits there for hours. I have to stop (ctrl c) and restart the program in order to get it working again.
Is there some condition that should be met before i attempt in.readLine()? Anything else?
Thanks kindly
Moose Jaw, Saskatchewan ;-)
20 years ago