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
…ponse times drastically eclipse-ee4j#5738

Signed-off-by: Jorge Bescos Gascon <jorge.bescos.gascon@oracle.com>
  • Loading branch information
jbescos committed Sep 23, 2024
1 parent 77c4da5 commit d375dda
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.net.Proxy;
import java.net.URL;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;

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

private static class DefaultConnectionFactory implements ConnectionFactory {

private final ConcurrentHashMap<URL, Object> 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 {
Object lock = locks.computeIfAbsent(url, u -> new Object());
synchronized (lock){
return (proxy == null) ? (HttpURLConnection) url.openConnection() : (HttpURLConnection) url.openConnection(proxy);
}
}
}

Expand Down

0 comments on commit d375dda

Please sign in to comment.