Skip to content

Commit efdcaec

Browse files
committed
Set max timeout to network connections
1 parent 6c30188 commit efdcaec

File tree

1 file changed

+11
-0
lines changed
  • com.archimatetool.editor/src/com/archimatetool/editor/utils

1 file changed

+11
-0
lines changed

com.archimatetool.editor/src/com/archimatetool/editor/utils/NetUtils.java

+11
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public final class NetUtils {
3939
// Store the default ProxySelector before we set ours
4040
private static final ProxySelector DEFAULT_PROXY_SELECTOR = ProxySelector.getDefault();
4141

42+
// Timeout in milliseconds
43+
private static final int CONNECTION_TIMEOUT = 20000;
44+
4245
private static Authenticator AUTHENTICATOR = new Authenticator() {
4346
@Override
4447
public PasswordAuthentication getPasswordAuthentication() {
@@ -72,6 +75,10 @@ public static void initialise() {
7275

7376
// And this one too, but not sure. I think it's for HTTP
7477
System.setProperty("jdk.http.auth.proxying.disabledSchemes", "");
78+
79+
// Set global timeouts. These might or might not work
80+
System.setProperty("sun.net.client.defaultConnectTimeout", Integer.toString(CONNECTION_TIMEOUT));
81+
System.setProperty("sun.net.client.defaultReadTimeout", Integer.toString(CONNECTION_TIMEOUT));
7582

7683
// Set default proxy now
7784
setDefaultProxy();
@@ -97,6 +104,10 @@ public static URLConnection openConnection(URL url) throws IOException {
97104
else {
98105
connection = url.openConnection();
99106
}
107+
108+
// Set timeouts, these will work even if the global poperties don't
109+
connection.setConnectTimeout(CONNECTION_TIMEOUT);
110+
connection.setReadTimeout(CONNECTION_TIMEOUT);
100111

101112
return connection;
102113
}

0 commit comments

Comments
 (0)