Wednesday, August 25, 2010

Java URL connection timeout - default timeout might save you from hanging

Many times, when you make a url connection or any connection that works over tcp ip (ftp, http etc) protocol, it is possible that your client just hangs.  It is frustrating to debug this kind of issue because, you do not get any exception from your application except it just hangs.  This can be a problem especially in production environments where there are firewalls between every single component and it is hard to trace network traffic.   

If you are using sun jdk.1.4 or above there is a way you can prevent your code from just hanging.  Best of all, you do not even have to make a code change.  The sun jvm has a way to specify default timeout values for the net client.   All you have to do is just add the following java parameters to the command line that starts your application.  
-Dsun.net.client.defaultConnectTimeout=TimeoutInMiliSec -Dsun.net.client.defaultReadTimeout=TimeoutInMiliSec 
 
This will force the client to timeout and hopefully your application logs the exception that gives enough clue to debug the issue.   For more information about specifying network properties in java check out the Networking Properties guide from sun/oracle.

6 comments:

casinononaams said...

First, we expect our future author to have a University degree and at least 2 years of expertise in custom writing. Nevertheless grade miners, many of them hesitate to order their essays online because they are afraid to get caught for cheating.

Lilla Wilkinson said...

Hiya! Order essays from https://expertpaperwriter.com/writemypaper4me-review/ and forget about your academic worries. Feel free to look over the completed paper and ask your essay writer any questions. We won't be satisfied until you are! Visit and get the best college essays today!

Goldyy said...

You can save good money when you order essays early. We are reliable custom essay writing service to buy essay cheap from college papers. The student is unsure on the topic at hand, so they want to hire an order essay service to ensure they don't affect their grades.

LasseNielsen said...

Sweet exposition composing administration was the main I've at any point utilized and will be the one to focus on. I was suspicious about requesting a paper from any site. On top of that my paper depended on a field that was more intricate and I couldn't actually say whether any article composing administration was outfitted with an author who is additionally proficient in IT. Yet, personal statements writing completed paper a day prior to the real due date and that was very acceptable.

casinononaams said...
This comment has been removed by the author.
whome2249 said...

There are assistants who are of no use, but this site https://rankmywriter.com/discount-codes/unemployed-professors-promo-code also helps a lot as a writer, and is very pleased with the result of the work, because on it he quickly and most importantly writes works of any complexity with high quality.