HttpClient и "Invalid use of SingleClientConnManager: connection still allocated."

апреля
17
2012
Метки: httpclient java

При использовании библиотеки Apache HtppClient возможно появление исключения "Invalid use of SingleClientConnManager: connection still allocated.":


W/SingleClientConnManager(25450): Invalid use of SingleClientConnManager: connection still allocated.
W/SingleClientConnManager(25450): Make sure to release the connection before allocating another one.

Решается эта проблема путем закрытия потока InputStream. То есть, допустим, у Вас есть код:


HttpResponse response = client.execute( requestMethod );
InputStream instream = response.getEntity().getContent();
// some code

Чтобы этот код не генерировал исключение "Invalid use of SingleClientConnManager: connection still allocated.", необходимо в конце его выполнения закрыть поток чтения данных:


HttpResponse response = client.execute( requestMethod );
InputStream instream = response.getEntity().getContent();
// some code
instream.close();

Напишите первое сообщение!

Вы должны войти под своим аккаунтом чтобы оставлять комментарии