@@ -55,9 +55,7 @@ public class DefaultEurekaClientHttpRequestFactorySupplier implements EurekaClie
5555
5656 private final Set <RequestConfigCustomizer > requestConfigCustomizers ;
5757
58- private final Object lock = new Object ();
59-
60- private volatile CloseableHttpClient sharedHttpClient ;
58+ private CloseableHttpClient sharedHttpClient ;
6159
6260 public DefaultEurekaClientHttpRequestFactorySupplier (TimeoutProperties timeoutProperties ,
6361 Set <RequestConfigCustomizer > requestConfigCustomizers ) {
@@ -66,38 +64,34 @@ public DefaultEurekaClientHttpRequestFactorySupplier(TimeoutProperties timeoutPr
6664 }
6765
6866 @ Override
69- public ClientHttpRequestFactory get (SSLContext sslContext , @ Nullable HostnameVerifier hostnameVerifier ) {
70- CloseableHttpClient httpClient ;
71- synchronized (this .lock ) {
72- httpClient = this .sharedHttpClient ;
73- if (httpClient == null ) {
74- HttpClientBuilder httpClientBuilder = HttpClientBuilder .create ();
75- if (sslContext != null || hostnameVerifier != null || timeoutProperties != null ) {
76- httpClientBuilder
77- .setConnectionManager (buildConnectionManager (sslContext , hostnameVerifier , timeoutProperties ));
78- }
79- httpClientBuilder .setDefaultRequestConfig (buildRequestConfig ());
80- httpClient = httpClientBuilder .build ();
81- this .sharedHttpClient = httpClient ;
67+ public synchronized ClientHttpRequestFactory get (SSLContext sslContext ,
68+ @ Nullable HostnameVerifier hostnameVerifier ) {
69+ CloseableHttpClient httpClient = this .sharedHttpClient ;
70+ if (httpClient == null ) {
71+ HttpClientBuilder httpClientBuilder = HttpClientBuilder .create ();
72+ if (sslContext != null || hostnameVerifier != null || timeoutProperties != null ) {
73+ httpClientBuilder
74+ .setConnectionManager (buildConnectionManager (sslContext , hostnameVerifier , timeoutProperties ));
8275 }
76+ httpClientBuilder .setDefaultRequestConfig (buildRequestConfig ());
77+ httpClient = httpClientBuilder .build ();
78+ this .sharedHttpClient = httpClient ;
8379 }
8480 HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory ();
8581 requestFactory .setHttpClient (httpClient );
8682 return requestFactory ;
8783 }
8884
8985 @ Override
90- public void close () {
91- synchronized (this .lock ) {
92- CloseableHttpClient httpClient = this .sharedHttpClient ;
93- this .sharedHttpClient = null ;
94- if (httpClient != null ) {
95- try {
96- httpClient .close ();
97- }
98- catch (IOException ex ) {
99- // best-effort close during shutdown; nothing actionable if it fails
100- }
86+ public synchronized void close () {
87+ CloseableHttpClient httpClient = this .sharedHttpClient ;
88+ this .sharedHttpClient = null ;
89+ if (httpClient != null ) {
90+ try {
91+ httpClient .close ();
92+ }
93+ catch (IOException ex ) {
94+ // best-effort close during shutdown; nothing actionable if it fails
10195 }
10296 }
10397 }
0 commit comments