您好,登錄后才能下訂單哦!
這篇文章主要講解了“怎么解決RestTemplate使用不當(dāng)引發(fā)的問題”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“怎么解決RestTemplate使用不當(dāng)引發(fā)的問題”吧!
系統(tǒng): SpringBoot開發(fā)的Web應(yīng)用;
ORM: JPA(Hibernate)
接口功能簡(jiǎn)述: 根據(jù)實(shí)體類ID到數(shù)據(jù)庫(kù)中查詢實(shí)體信息,然后使用RestTemplate調(diào)用外部系統(tǒng)接口獲取數(shù)據(jù)。
瀏覽器頁(yè)面有時(shí)報(bào)504 GateWay Timeout錯(cuò)誤,刷新多次后,則總是timeout
數(shù)據(jù)庫(kù)連接池報(bào)連接耗盡異常
調(diào)用外部系統(tǒng)時(shí)有時(shí)報(bào)502 Bad GateWay錯(cuò)誤
為便于描述將本系統(tǒng)稱為A,外部系統(tǒng)稱為B。
這三個(gè)問題環(huán)環(huán)相扣,導(dǎo)火索是第3個(gè)問題,然后導(dǎo)致第2個(gè)問題,最后導(dǎo)致出現(xiàn)第3個(gè)問題;
原因簡(jiǎn)述: 第3個(gè)問題是由于Nginx負(fù)載下沒有掛系統(tǒng)B,導(dǎo)致本系統(tǒng)在請(qǐng)求外部系統(tǒng)時(shí)報(bào)502錯(cuò)誤,而A沒有正確處理異常,導(dǎo)致http請(qǐng)求無法正常關(guān)閉,而springboot默認(rèn)打開openSessionInView, 只有調(diào)用A的請(qǐng)求關(guān)閉時(shí)才會(huì)關(guān)閉數(shù)據(jù)庫(kù)連接,而此時(shí)調(diào)用A的請(qǐng)求沒有關(guān)閉,導(dǎo)致數(shù)據(jù)庫(kù)連接沒有關(guān)閉。
這里主要分析第1個(gè)問題:為什么請(qǐng)求A的連接出現(xiàn)504 Timeout.
通過日志看到A在調(diào)用B時(shí)出現(xiàn)阻塞,直到timeout,打印出線程堆棧查看:
線程阻塞在AbstractConnPool類getPoolEntryBlocking方法中
private E getPoolEntryBlocking( final T route, final Object state, final long timeout, final TimeUnit timeUnit, final Future<E> future) throws IOException, InterruptedException, TimeoutException { Date deadline = null; if (timeout > 0) { deadline = new Date (System.currentTimeMillis() + timeUnit.toMillis(timeout)); } this.lock.lock(); try { //根據(jù)route獲取route對(duì)應(yīng)的連接池 final RouteSpecificPool<T, C, E> pool = getPool(route); E entry; for (;;) { Asserts.check(!this.isShutDown, "Connection pool shut down"); for (;;) { //獲取可用的連接 entry = pool.getFree(state); if (entry == null) { break; } // 判斷連接是否過期,如過期則關(guān)閉并從可用連接集合中刪除 if (entry.isExpired(System.currentTimeMillis())) { entry.close(); } if (entry.isClosed()) { this.available.remove(entry); pool.free(entry, false); } else { break; } } // 如果從連接池中獲取到可用連接,更新可用連接和待釋放連接集合 if (entry != null) { this.available.remove(entry); this.leased.add(entry); onReuse(entry); return entry; } // 如果沒有可用連接,則創(chuàng)建新連接 final int maxPerRoute = getMax(route); // 創(chuàng)建新連接之前,檢查是否超過每個(gè)route連接池大小,如果超過,則刪除可用連接集合相應(yīng)數(shù)量的連接(從總的可用連接集合和每個(gè)route的可用連接集合中刪除) final int excess = Math.max(0, pool.getAllocatedCount() + 1 - maxPerRoute); if (excess > 0) { for (int i = 0; i < excess; i++) { final E lastUsed = pool.getLastUsed(); if (lastUsed == null) { break; } lastUsed.close(); this.available.remove(lastUsed); pool.remove(lastUsed); } } if (pool.getAllocatedCount() < maxPerRoute) { //比較總的可用連接數(shù)量與總的可用連接集合大小,釋放多余的連接資源 final int totalUsed = this.leased.size(); final int freeCapacity = Math.max(this.maxTotal - totalUsed, 0); if (freeCapacity > 0) { final int totalAvailable = this.available.size(); if (totalAvailable > freeCapacity - 1) { if (!this.available.isEmpty()) { final E lastUsed = this.available.removeLast(); lastUsed.close(); final RouteSpecificPool<T, C, E> otherpool = getPool(lastUsed.getRoute()); otherpool.remove(lastUsed); } } // 真正創(chuàng)建連接的地方 final C conn = this.connFactory.create(route); entry = pool.add(conn); this.leased.add(entry); return entry; } } //如果已經(jīng)超過了每個(gè)route的連接池大小,則加入隊(duì)列等待有可用連接時(shí)被喚醒或直到某個(gè)終止時(shí)間 boolean success = false; try { if (future.isCancelled()) { throw new InterruptedException("Operation interrupted"); } pool.queue(future); this.pending.add(future); if (deadline != null) { success = this.condition.awaitUntil(deadline); } else { this.condition.await(); success = true; } if (future.isCancelled()) { throw new InterruptedException("Operation interrupted"); } } finally { //如果到了終止時(shí)間或有被喚醒時(shí),則出隊(duì),加入下次循環(huán) pool.unqueue(future); this.pending.remove(future); } // 處理異常喚醒和超時(shí)情況 if (!success && (deadline != null && deadline.getTime() <= System.currentTimeMillis())) { break; } } throw new TimeoutException("Timeout waiting for connection"); } finally { this.lock.unlock(); } }
getPoolEntryBlocking方法用于獲取連接,主要有三步:(1).檢查可用連接集合中是否有可重復(fù)使用的連接,如果有則獲取連接,返回. (2)創(chuàng)建新連接,注意同時(shí)需要檢查可用連接集合(分為每個(gè)route的和全局的)是否有多余的連接資源,如果有,則需要釋放。(3)加入隊(duì)列等待;
從線程堆??梢钥闯觯?個(gè)問題是由于走到了第3步。開始時(shí)是有時(shí)會(huì)報(bào)504異常,刷新多次后會(huì)一直報(bào)504異常,經(jīng)過跟蹤調(diào)試發(fā)現(xiàn)前幾次會(huì)成功獲取到連接,而連接池滿后,后面的請(qǐng)求會(huì)阻塞。正常情況下當(dāng)前面的連接釋放到連接池后,后面的請(qǐng)求會(huì)得到連接資源繼續(xù)執(zhí)行,可現(xiàn)實(shí)是后面的連接一直處于等待狀態(tài),猜想可能是由于連接一直未釋放導(dǎo)致。
我們來看一下連接在什么時(shí)候會(huì)釋放。
由于在調(diào)外部系統(tǒng)B時(shí),使用的是RestTemplate的getForObject方法,從此入手跟蹤調(diào)試看一看。
@Override public <T> T getForObject(String url, Class<T> responseType, Object... uriVariables) throws RestClientException { RequestCallback requestCallback = acceptHeaderRequestCallback(responseType); HttpMessageConverterExtractor<T> responseExtractor = new HttpMessageConverterExtractor<T>(responseType, getMessageConverters(), logger); return execute(url, HttpMethod.GET, requestCallback, responseExtractor, uriVariables); } @Override public <T> T getForObject(String url, Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException { RequestCallback requestCallback = acceptHeaderRequestCallback(responseType); HttpMessageConverterExtractor<T> responseExtractor = new HttpMessageConverterExtractor<T>(responseType, getMessageConverters(), logger); return execute(url, HttpMethod.GET, requestCallback, responseExtractor, uriVariables); } @Override public <T> T getForObject(URI url, Class<T> responseType) throws RestClientException { RequestCallback requestCallback = acceptHeaderRequestCallback(responseType); HttpMessageConverterExtractor<T> responseExtractor = new HttpMessageConverterExtractor<T>(responseType, getMessageConverters(), logger); return execute(url, HttpMethod.GET, requestCallback, responseExtractor); }
getForObject都調(diào)用了execute方法(其實(shí)RestTemplate的其它http請(qǐng)求方法調(diào)用的也是execute方法)
@Override public <T> T execute(String url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor, Object... uriVariables) throws RestClientException { URI expanded = getUriTemplateHandler().expand(url, uriVariables); return doExecute(expanded, method, requestCallback, responseExtractor); } @Override public <T> T execute(String url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor, Map<String, ?> uriVariables) throws RestClientException { URI expanded = getUriTemplateHandler().expand(url, uriVariables); return doExecute(expanded, method, requestCallback, responseExtractor); } @Override public <T> T execute(URI url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor) throws RestClientException { return doExecute(url, method, requestCallback, responseExtractor); }
所有execute方法都調(diào)用了同一個(gè)doExecute方法
protected <T> T doExecute(URI url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor) throws RestClientException { Assert.notNull(url, "'url' must not be null"); Assert.notNull(method, "'method' must not be null"); ClientHttpResponse response = null; try { ClientHttpRequest request = createRequest(url, method); if (requestCallback != null) { requestCallback.doWithRequest(request); } response = request.execute(); handleResponse(url, method, response); if (responseExtractor != null) { return responseExtractor.extractData(response); } else { return null; } } catch (IOException ex) { String resource = url.toString(); String query = url.getRawQuery(); resource = (query != null ? resource.substring(0, resource.indexOf('?')) : resource); throw new ResourceAccessException("I/O error on " + method.name() + " request for \"" + resource + "\": " + ex.getMessage(), ex); } finally { if (response != null) { response.close(); } } }
進(jìn)入到request.execute()方法中,對(duì)應(yīng)抽象類org.springframework.http.client.AbstractClientHttpRequest的execute方法
@Override public final ClientHttpResponse execute() throws IOException { assertNotExecuted(); ClientHttpResponse result = executeInternal(this.headers); this.executed = true; return result; }
調(diào)用內(nèi)部方法executeInternal,executeInternal方法是一個(gè)抽象方法,由子類實(shí)現(xiàn)(restTemplate內(nèi)部的http調(diào)用實(shí)現(xiàn)方式有多種)。進(jìn)入executeInternal方法,到達(dá)抽象類 org.springframework.http.client.AbstractBufferingClientHttpRequest中
protected ClientHttpResponse executeInternal(HttpHeaders headers) throws IOException { byte[] bytes = this.bufferedOutput.toByteArray(); if (headers.getContentLength() < 0) { headers.setContentLength(bytes.length); } ClientHttpResponse result = executeInternal(headers, bytes); this.bufferedOutput = null; return result; }
緩充請(qǐng)求body數(shù)據(jù),調(diào)用內(nèi)部方法executeInternal
ClientHttpResponse result = executeInternal(headers, bytes);
executeInternal方法中調(diào)用另一個(gè)executeInternal方法,它也是一個(gè)抽象方法
進(jìn)入executeInternal方法,此方法由org.springframework.http.client.AbstractBufferingClientHttpRequest的子類org.springframework.http.client.InterceptingClientHttpRequest實(shí)現(xiàn)
protected final ClientHttpResponse executeInternal(HttpHeaders headers, byte[] bufferedOutput) throws IOException { InterceptingRequestExecution requestExecution = new InterceptingRequestExecution(); return requestExecution.execute(this, bufferedOutput); }
實(shí)例化了一個(gè)帶攔截器的請(qǐng)求執(zhí)行對(duì)象InterceptingRequestExecution
public ClientHttpResponse execute(HttpRequest request, final byte[] body) throws IOException { // 如果有攔截器,則執(zhí)行攔截器并返回結(jié)果 if (this.iterator.hasNext()) { ClientHttpRequestInterceptor nextInterceptor = this.iterator.next(); return nextInterceptor.intercept(request, body, this); } else { // 如果沒有攔截器,則通過requestFactory創(chuàng)建request對(duì)象并執(zhí)行 ClientHttpRequest delegate = requestFactory.createRequest(request.getURI(), request.getMethod()); for (Map.Entry<String, List<String>> entry : request.getHeaders().entrySet()) { List<String> values = entry.getValue(); for (String value : values) { delegate.getHeaders().add(entry.getKey(), value); } } if (body.length > 0) { if (delegate instanceof StreamingHttpOutputMessage) { StreamingHttpOutputMessage streamingOutputMessage = (StreamingHttpOutputMessage) delegate; streamingOutputMessage.setBody(new StreamingHttpOutputMessage.Body() { @Override public void writeTo(final OutputStream outputStream) throws IOException { StreamUtils.copy(body, outputStream); } }); } else { StreamUtils.copy(body, delegate.getBody()); } } return delegate.execute(); } }
InterceptingClientHttpRequest的execute方法,先執(zhí)行攔截器,最后執(zhí)行真正的請(qǐng)求對(duì)象(什么是真正的請(qǐng)求對(duì)象?見后面攔截器的設(shè)計(jì)部分)。
看一下RestTemplate的配置:
RestTemplateBuilder builder = new RestTemplateBuilder(); return builder .setConnectTimeout(customConfig.getRest().getConnectTimeOut()) .setReadTimeout(customConfig.getRest().getReadTimeout()) .interceptors(restTemplateLogInterceptor) .errorHandler(new ThrowErrorHandler()) .build(); }
可以看到配置了連接超時(shí),讀超時(shí),攔截器,和錯(cuò)誤處理器。
看一下攔截器的實(shí)現(xiàn):
public ClientHttpResponse intercept(HttpRequest httpRequest, byte[] bytes, ClientHttpRequestExecution clientHttpRequestExecution) throws IOException { // 打印訪問前日志 ClientHttpResponse execute = clientHttpRequestExecution.execute(httpRequest, bytes); if (如果返回碼不是200) { // 拋出自定義運(yùn)行時(shí)異常 } // 打印訪問后日志 return execute; }
可以看到當(dāng)返回碼不是200時(shí),拋出異常。還記得RestTemplate中的doExecute方法吧,此處如果拋出異常,雖然會(huì)執(zhí)行doExecute方法中的finally代碼,但由于返回的response為null(其實(shí)是有response的),沒有關(guān)閉response,所以這里不能拋出異常,如果確實(shí)想拋出異常,可以在錯(cuò)誤處理器errorHandler中拋出,這樣確保response能正常返回和關(guān)閉。
知道了原因,我們?cè)賮砜匆幌翿estTemplate在什么時(shí)候決定使用什么http框架。其實(shí)在通過RestTemplateBuilder實(shí)例化RestTemplate對(duì)象時(shí)就決定了。
看一下RestTemplateBuilder的build方法
public RestTemplate build() { return build(RestTemplate.class); } public <T extends RestTemplate> T build(Class<T> restTemplateClass) { return configure(BeanUtils.instantiate(restTemplateClass)); }
可以看到在實(shí)例化RestTemplate對(duì)象之后,進(jìn)行配置。可以指定requestFactory,也可以自動(dòng)探測(cè)
public <T extends RestTemplate> T configure(T restTemplate) { // 配置requestFactory configureRequestFactory(restTemplate); .....省略其它無關(guān)代碼 } private void configureRequestFactory(RestTemplate restTemplate) { ClientHttpRequestFactory requestFactory = null; if (this.requestFactory != null) { requestFactory = this.requestFactory; } else if (this.detectRequestFactory) { requestFactory = detectRequestFactory(); } if (requestFactory != null) { ClientHttpRequestFactory unwrappedRequestFactory = unwrapRequestFactoryIfNecessary( requestFactory); for (RequestFactoryCustomizer customizer : this.requestFactoryCustomizers) { customizer.customize(unwrappedRequestFactory); } restTemplate.setRequestFactory(requestFactory); } }
看一下detectRequestFactory方法
private ClientHttpRequestFactory detectRequestFactory() { for (Map.Entry<String, String> candidate : REQUEST_FACTORY_CANDIDATES .entrySet()) { ClassLoader classLoader = getClass().getClassLoader(); if (ClassUtils.isPresent(candidate.getKey(), classLoader)) { Class<?> factoryClass = ClassUtils.resolveClassName(candidate.getValue(), classLoader); ClientHttpRequestFactory requestFactory = (ClientHttpRequestFactory) BeanUtils .instantiate(factoryClass); initializeIfNecessary(requestFactory); return requestFactory; } } return new SimpleClientHttpRequestFactory(); }
循環(huán)REQUEST_FACTORY_CANDIDATES集合,檢查classpath類路徑中是否存在相應(yīng)的jar包,如果存在,則創(chuàng)建相應(yīng)框架的封裝類對(duì)象。如果都不存在,則返回使用JDK方式實(shí)現(xiàn)的RequestFactory對(duì)象。
看一下REQUEST_FACTORY_CANDIDATES集合
private static final Map<String, String> REQUEST_FACTORY_CANDIDATES; static { Map<String, String> candidates = new LinkedHashMap<String, String>(); candidates.put("org.apache.http.client.HttpClient", "org.springframework.http.client.HttpComponentsClientHttpRequestFactory"); candidates.put("okhttp3.OkHttpClient", "org.springframework.http.client.OkHttp3ClientHttpRequestFactory"); candidates.put("com.squareup.okhttp.OkHttpClient", "org.springframework.http.client.OkHttpClientHttpRequestFactory"); candidates.put("io.netty.channel.EventLoopGroup", "org.springframework.http.client.Netty4ClientHttpRequestFactory"); REQUEST_FACTORY_CANDIDATES = Collections.unmodifiableMap(candidates); }
可以看到共有四種Http調(diào)用實(shí)現(xiàn)方式,在配置RestTemplate時(shí)可指定,并在類路徑中提供相應(yīng)的實(shí)現(xiàn)jar包。
再看一下InterceptingRequestExecution類的execute方法。
public ClientHttpResponse execute(HttpRequest request, final byte[] body) throws IOException { // 如果有攔截器,則執(zhí)行攔截器并返回結(jié)果 if (this.iterator.hasNext()) { ClientHttpRequestInterceptor nextInterceptor = this.iterator.next(); return nextInterceptor.intercept(request, body, this); } else { // 如果沒有攔截器,則通過requestFactory創(chuàng)建request對(duì)象并執(zhí)行 ClientHttpRequest delegate = requestFactory.createRequest(request.getURI(), request.getMethod()); for (Map.Entry<String, List<String>> entry : request.getHeaders().entrySet()) { List<String> values = entry.getValue(); for (String value : values) { delegate.getHeaders().add(entry.getKey(), value); } } if (body.length > 0) { if (delegate instanceof StreamingHttpOutputMessage) { StreamingHttpOutputMessage streamingOutputMessage = (StreamingHttpOutputMessage) delegate; streamingOutputMessage.setBody(new StreamingHttpOutputMessage.Body() { @Override public void writeTo(final OutputStream outputStream) throws IOException { StreamUtils.copy(body, outputStream); } }); } else { StreamUtils.copy(body, delegate.getBody()); } } return delegate.execute(); } }
大家可能會(huì)有疑問,傳入的對(duì)象已經(jīng)是request對(duì)象了,為什么在沒有攔截器時(shí)還要再創(chuàng)建一遍request對(duì)象呢?
其實(shí)傳入的request對(duì)象在有攔截器的時(shí)候是InterceptingClientHttpRequest對(duì)象,沒有攔截器時(shí),則直接是包裝了各個(gè)http調(diào)用實(shí)現(xiàn)框的Request。如HttpComponentsClientHttpRequest、OkHttp3ClientHttpRequest等。當(dāng)有攔截器時(shí),會(huì)執(zhí)行攔截器,攔截器可以有多個(gè),而這里 this.iterator.hasNext() 不是一個(gè)循環(huán),為什么呢?秘密在于攔截器的intercept方法。
ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException;
此方法包含request,body,execution。exection類型為ClientHttpRequestExecution接口,上面的InterceptingRequestExecution便實(shí)現(xiàn)了此接口,這樣在調(diào)用攔截器時(shí),傳入exection對(duì)象本身,然后再調(diào)一次execute方法,再判斷是否仍有攔截器,如果有,再執(zhí)行下一個(gè)攔截器,將所有攔截器執(zhí)行完后,再生成真正的request對(duì)象,執(zhí)行http調(diào)用。
那如果沒有攔截器呢?
上面已經(jīng)知道RestTemplate在實(shí)例化時(shí)會(huì)實(shí)例化RequestFactory,當(dāng)發(fā)起http請(qǐng)求時(shí),會(huì)執(zhí)行restTemplate的doExecute方法,此方法中會(huì)創(chuàng)建Request,而createRequest方法中,首先會(huì)獲取RequestFactory
// org.springframework.http.client.support.HttpAccessor protected ClientHttpRequest createRequest(URI url, HttpMethod method) throws IOException { ClientHttpRequest request = getRequestFactory().createRequest(url, method); if (logger.isDebugEnabled()) { logger.debug("Created " + method.name() + " request for \"" + url + "\""); } return request; } // org.springframework.http.client.support.InterceptingHttpAccessor public ClientHttpRequestFactory getRequestFactory() { ClientHttpRequestFactory delegate = super.getRequestFactory(); if (!CollectionUtils.isEmpty(getInterceptors())) { return new InterceptingClientHttpRequestFactory(delegate, getInterceptors()); } else { return delegate; } }
看一下RestTemplate與這兩個(gè)類的關(guān)系就知道調(diào)用關(guān)系了。
而在獲取到RequestFactory之后,判斷有沒有攔截器,如果有,則創(chuàng)建InterceptingClientHttpRequestFactory對(duì)象,而此RequestFactory在createRequest時(shí),會(huì)創(chuàng)建InterceptingClientHttpRequest對(duì)象,這樣就可以先執(zhí)行攔截器,最后執(zhí)行創(chuàng)建真正的Request對(duì)象執(zhí)行http調(diào)用。
以HttpComponents為底層Http調(diào)用實(shí)現(xiàn)的邏輯流程圖。
流程圖說明:
RestTemplate可以根據(jù)配置來實(shí)例化對(duì)應(yīng)的RequestFactory,包括apache httpComponents、OkHttp3、Netty等實(shí)現(xiàn)。
RestTemplate與HttpComponents銜接的類是HttpClient,此類是apache httpComponents提供給用戶使用,執(zhí)行http調(diào)用。HttpClient是創(chuàng)建RequestFactory對(duì)象時(shí)通過HttpClientBuilder實(shí)例化的,在實(shí)例化HttpClient對(duì)象時(shí),實(shí)例化了HttpClientConnectionManager和多個(gè)ClientExecChain,HttpRequestExecutor、HttpProcessor以及一些策略。
當(dāng)發(fā)起請(qǐng)求時(shí),由requestFactory實(shí)例化httpRequest,然后依次執(zhí)行ClientexecChain,常用的有四種:
RedirectExec
:請(qǐng)求跳轉(zhuǎn);根據(jù)上次響應(yīng)結(jié)果和跳轉(zhuǎn)策略決定下次跳轉(zhuǎn)的地址,默認(rèn)最大執(zhí)行50次跳轉(zhuǎn);
RetryExec
:決定出現(xiàn)I/O錯(cuò)誤的請(qǐng)求是否再次執(zhí)行
ProtocolExec
: 填充必要的http請(qǐng)求header,處理http響應(yīng)header,更新會(huì)話狀態(tài)
MainClientExec
:請(qǐng)求執(zhí)行鏈中最后一個(gè)節(jié)點(diǎn);從連接池CPool中獲取連接,執(zhí)行請(qǐng)求調(diào)用,并返回請(qǐng)求結(jié)果;
PoolingHttpClientConnectionManager用于管理連接池,包括連接池初始化,獲取連接,獲取連接,打開連接,釋放連接,關(guān)閉連接池等操作。
CPool代表連接池,但連接并不保存在CPool中;CPool中維護(hù)著三個(gè)連接狀態(tài)集合:leased(租用的,即待釋放的)/available(可用的)/pending(等待的),用于記錄所有連接的狀態(tài);并且維護(hù)著每個(gè)Route對(duì)應(yīng)的連接池RouteSpecificPool;
RouteSpecificPool是連接真正存放的地方,內(nèi)部同樣也維護(hù)著三個(gè)連接狀態(tài)集合,但只記錄屬于本route的連接。
HttpComponents將連接按照route劃分連接池,有利于資源隔離,使每個(gè)route請(qǐng)求相互不影響;
感謝各位的閱讀,以上就是“怎么解決RestTemplate使用不當(dāng)引發(fā)的問題”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì)怎么解決RestTemplate使用不當(dāng)引發(fā)的問題這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。