I was looking for a complete example CloseableHttpClientusing try-with-resources. I am confused if closing CloseableHttpClientalso closes the object CloseableHttpResponsethat will be created when called httpclient.execute(post). Do I need to wrap CloseableHttpResponsein try-with-resources too?
CloseableHttpClient
CloseableHttpResponse
httpclient.execute(post)
Example:
try(CloseableHttpClient httpclient = HttpClients.custom().build()) { HttpPost post = new HttpPost(url); CloseableHttpResponse res = httpclient.execute(post); // do something with res } catch (Throwable e) { // do something with error }
If you want the answer to participate in a try-with-resource, you do. Although after you catch the Exceptions already, you can end up with} - no extra trick is required.
, close () CloseableHttpResponse
close ()
. Throwable - .
Source: https://habr.com/ru/post/1621459/More articles:https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1621454/android-implementing-setonitemselectedlistener-to-make-dynamic-spinner&usg=ALkJrhiTzzTcf8ecbbG4rTkGlc6bb42HagJumblr API gives a bad request when sending an image to Tumblr - androidhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1621456/array-of-keyvalue-pairs-to-object&usg=ALkJrhi1l8lNvGSqhsYtBPocDBwjak-leQDoes the generator generator not work with yomen? - generatorInvalid error types in Android: Object and int - javaОшибка синтаксического анализа паролей с помощью webpack и реакция, даже с использованием загрузчика Babel - webpackLucene: null when adding a field with DocValues - javaHow to solve multiple independent time series simultaneously using scikit linear regression model - pythonConverting nested Scala types to Java types - javaSetting a circuit breaker with a service activator - javaAll Articles