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.