Skip to content

Commit 4f588c2

Browse files
committed
Jersey update from 3.1.3 to 3.1.4 slows down our external service response times drastically #5738
Signed-off-by: Jorge Bescos Gascon <[email protected]>
1 parent 77c4da5 commit 4f588c2

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

core-client/src/main/java/org/glassfish/jersey/client/HttpUrlConnectorProvider.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.net.Proxy;
2222
import java.net.URL;
2323
import java.util.Map;
24+
import java.util.concurrent.ConcurrentHashMap;
2425
import java.util.logging.Logger;
2526

2627
import jakarta.ws.rs.client.Client;
@@ -295,9 +296,23 @@ default HttpURLConnection getConnection(URL url, Proxy proxy) throws IOException
295296

296297
private static class DefaultConnectionFactory implements ConnectionFactory {
297298

299+
private final ConcurrentHashMap<URL, Object> locks = new ConcurrentHashMap<>();
300+
298301
@Override
299302
public HttpURLConnection getConnection(final URL url) throws IOException {
300-
return (HttpURLConnection) url.openConnection();
303+
return connect(url, null);
304+
}
305+
306+
@Override
307+
public HttpURLConnection getConnection(URL url, Proxy proxy) throws IOException {
308+
return connect(url, proxy);
309+
}
310+
311+
private HttpURLConnection connect(URL url, Proxy proxy) throws IOException {
312+
Object lock = locks.computeIfAbsent(url, u -> new Object());
313+
synchronized (lock){
314+
return (proxy == null) ? (HttpURLConnection) url.openConnection() : (HttpURLConnection) url.openConnection(proxy);
315+
}
301316
}
302317
}
303318

0 commit comments

Comments
 (0)