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 #5738

Signed-off-by: Jorge Bescos Gascon <jorge.bescos.gascon@oracle.com>
  • Loading branch information
jbescos committed Sep 23, 2024
1 parent 77c4da5 commit 7fedc69
Showing 1 changed file with 17 additions and 2 deletions.
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 @@ -258,7 +259,7 @@ protected Connector createHttpUrlConnector(Client client, ConnectionFactory conn
* via {@link #connectionFactory(ConnectionFactory)} method.
*/
public interface ConnectionFactory {

/**
* Get a {@link java.net.HttpURLConnection} for a given URL.
* <p>
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 7fedc69

Please sign in to comment.