I'm trying to open an HTTP connection to a web site in a Java Enterprise application (deployed on a Wildfly 8.2 application server). I use a fairly standard tool to do this - the Jsoup library. Most of the time, the connection is opened without a problem, and I can read and parse the web site content (for further processing).
However, if once the open fails (times out) - it will never again succeed, until the full restart of the application. Any attempt to open a connection to the same website will fail with the same exception again. As if the application memorized the inaccessible status of the web site, and stuck to this hypothesis, without trying again. (I am fairly confident, that even when the web site is accessible, the application still throws this exception again and again.)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.TwoStacksPlainSocketImpl.socketConnect(Native Method) [rt.jar:1.8.0_31]
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) [rt.jar:1.8.0_31]
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) [rt.jar:1.8.0_31]
at java.net.AbstractPlainSocketImpl.connect(Unknown Source) [rt.jar:1.8.0_31]
at java.net.PlainSocketImpl.connect(Unknown Source) [rt.jar:1.8.0_31]
at java.net.SocksSocketImpl.connect(Unknown Source) [rt.jar:1.8.0_31]
at java.net.Socket.connect(Unknown Source) [rt.jar:1.8.0_31]
at sun.net.NetworkClient.doConnect(Unknown Source) [rt.jar:1.8.0_31]
at sun.net.www.http.HttpClient.openServer(Unknown Source) [rt.jar:1.8.0_31]
at sun.net.www.http.HttpClient.openServer(Unknown Source) [rt.jar:1.8.0_31]
at sun.net.www.http.HttpClient.<init>(Unknown Source) [rt.jar:1.8.0_31]
at sun.net.www.http.HttpClient.New(Unknown Source) [rt.jar:1.8.0_31]
at sun.net.www.http.HttpClient.New(Unknown Source) [rt.jar:1.8.0_31]
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source) [rt.jar:1.8.0_31]
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source) [rt.jar:1.8.0_31]
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source) [rt.jar:1.8.0_31]
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source) [rt.jar:1.8.0_31]
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:449) [jsoup-1.8.1.jar:]
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:434) [jsoup-1.8.1.jar:]
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:181) [jsoup-1.8.1.jar:]
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:170) [jsoup-1.8.1.jar:]
It turned out, that (in this specific case) the network was configured incorrectly. Not only JVM, several other programs experienced network issues.