Skip to content

Commit

Permalink
Jersey update from 3.1.3 to 3.1.4 slows down our external service res…
Browse files Browse the repository at this point in the history
…eclipse-ee4j#5746

Signed-off-by: Jorge Bescos Gascon <[email protected]>
  • Loading branch information
jbescos committed Sep 26, 2024
1 parent 2fd3e28 commit b35fe36
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import java.net.Proxy;
import java.net.URL;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Logger;

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

private static class DefaultConnectionFactory implements ConnectionFactory {

private final ConcurrentHashMap<URL, Lock> locks = new ConcurrentHashMap<>();

@Override
public HttpURLConnection getConnection(final URL url) throws IOException {
return (HttpURLConnection) url.openConnection();
return connect(url, null);
}

@Override
public HttpURLConnection getConnection(URL url, Proxy proxy) throws IOException {
return connect(url, proxy);
}

private HttpURLConnection connect(URL url, Proxy proxy) throws IOException {
Lock lock = locks.computeIfAbsent(url, u -> new ReentrantLock());
lock.lock();
try {
return (proxy == null) ? (HttpURLConnection) url.openConnection() : (HttpURLConnection) url.openConnection(proxy);
} finally {
lock.unlock();
}
}
}

Expand Down

0 comments on commit b35fe36

Please sign in to comment.