I have some problems with my app. In market reports often appears ANR repostr with HttpClient errors. There are
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2016) at org.apache.http.impl.conn.tsccm.WaitingThread.await(WaitingThread.java:159) at org.apache.http.impl.conn.tsccm.ConnPoolByRoute.getEntryBlocking(ConnPoolByRoute.java:339) at org.apache.http.impl.conn.tsccm.ConnPoolByRoute$1.getPoolEntry(ConnPoolByRoute.java:238) at org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager$1.getConnection(ThreadSafeClientConnManager.java:175) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:325) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:580) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:512) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:490)
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2022) at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:413) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1014) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1074) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:574) at java.lang.Thread.run(Thread.java:1020)
DALVIK THREADS: (mutexes: tll=0 tsl=0 tscl=0 ghl=0 hwl=0 hwll=0) "main" prio=5 tid=1 NATIVE | group="main" sCount=1 dsCount=0 obj=0x40027550 self=0xcfc0 | sysTid=2557 nice=0 sched=0/0 cgrp=default handle=-1345006240 | schedstat=( 6440246597 181026702867 12047 ) at org.apache.harmony.luni.platform.OSNetworkSystem.connect(Native Method) at dalvik.system.BlockGuard$WrappedNetworkSystem.connect(BlockGuard.java:357) at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:207) at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:440) at java.net.Socket.connect(Socket.java:1013) at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119) at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:143) at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:359) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465
There are any approach to avoid this errors? Maybe some best practice how to work with httpClient? In my app I am usung:
public ApiImpl() {
this.httpClient = new DefaultHttpClient();
ClientConnectionManager mgr = httpClient.getConnectionManager();
HttpParams params = httpClient.getParams();
this.httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(params, mgr.getSchemeRegistry()), params);
}
public class Client {
private static Api api;
private static Client instance = null;
public static Client getInstance() {
if (instance == null) {
instance = new Client();
}
return instance;
}
private Client() {
api = new ApiImpl();
}
}
then in code I am useing following
Client client = Client.getInstance();
client.do();