I am running into a problem where various places in my application involving http and ftp connections are hanging indefinitely (observed for hours at a time before killing the java process) on java.net.SocketInputStream.socketRead0.
I'd like to override the default socket timeout of 0 globally so that I don't have to set it in every single location where I initiate a connection. Is there some global Java property or method I can call to set the default socket timeout to something other than 0?
It depends on how your application creates sockets. If your application code uses URLConnection then you can set default timeout using JVM properties:
-Dsun.net.client.defaultReadTimeout=30000
-Dsun.net.client.defaultConnectTimeout=5000
This properties are implementation specific but still works for latest Oracle/OpenJDK.
https://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With