A similar exception message (since at least Apache Jarkata Commons HTTP Client 4.2):
java.lang.IllegalStateException: Invalid use of BasicClientConnManager: connection still allocated. Make sure to release the connection before allocating another one.
This exception may occur if two or more threads interact with one org.apache.http.impl.client.DefaultHttpClient .
How can you create a streaming application 4.2 DefaultHttpClient (thread safe in the sense that two or more threads can interact with it without receiving an error message)? Provide the DefaultHttpClient connection ClientConnectionManager in the form org.apache.http.impl.conn.PoolingClientConnectionManager !
import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.params.HttpConnectionParams; import org.apache.http.client.HttpClient; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.conn.PoolingClientConnectionManager; import org.apache.http.impl.conn.SchemeRegistryFactory; import org.apache.http.params.HttpParams; import org.apache.http.client.methods.HttpGet; public class MyComponent { private HttpClient client; { PoolingClientConnectionManager conMan = new PoolingClientConnectionManager( SchemeRegistryFactory.createDefault() ); conMan.setMaxTotal(200); conMan.setDefaultMaxPerRoute(200); client = new DefaultHttpClient(conMan);
Abdull Feb 07 '13 at 22:50 2013-02-07 22:50
source share