Skip to content

Commit cb3c4f2

Browse files
committed
Jersey update from 3.1.3 to 3.1.4 slows down our external service res… eclipse-ee4j#5746
Signed-off-by: Jorge Bescos Gascon <[email protected]>
1 parent 2fd3e28 commit cb3c4f2

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
import java.net.Proxy;
2222
import java.net.URL;
2323
import java.util.Map;
24+
import java.util.concurrent.ConcurrentHashMap;
25+
import java.util.concurrent.locks.Lock;
26+
import java.util.concurrent.locks.ReentrantLock;
2427
import java.util.logging.Logger;
2528

2629
import javax.ws.rs.client.Client;
@@ -295,9 +298,26 @@ default HttpURLConnection getConnection(URL url, Proxy proxy) throws IOException
295298

296299
private static class DefaultConnectionFactory implements ConnectionFactory {
297300

301+
private final ConcurrentHashMap<URL, Lock> locks = new ConcurrentHashMap<>();
302+
298303
@Override
299304
public HttpURLConnection getConnection(final URL url) throws IOException {
300-
return (HttpURLConnection) url.openConnection();
305+
return connect(url, null);
306+
}
307+
308+
@Override
309+
public HttpURLConnection getConnection(URL url, Proxy proxy) throws IOException {
310+
return connect(url, proxy);
311+
}
312+
313+
private HttpURLConnection connect(URL url, Proxy proxy) throws IOException {
314+
Lock lock = locks.computeIfAbsent(url, u -> new ReentrantLock());
315+
lock.lock();
316+
try {
317+
return (proxy == null) ? (HttpURLConnection) url.openConnection() : (HttpURLConnection) url.openConnection(proxy);
318+
} finally {
319+
lock.unlock();
320+
}
301321
}
302322
}
303323

0 commit comments

Comments
 (0)