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();

Напишіть перше повідомлення!

Ви повинні увійти під своїм аккаунтом щоб залишати коментарі