I recently excluded this exception from the application:
java.lang.OutOfMemoryError: pthread_create (stack size 16384 bytes) failed: Try again
at java.lang.VMThread.create(VMThread.java)
at java.lang.Thread.start(Thread.java:1029)
at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:920)
at java.util.concurrent.ThreadPoolExecutor.processWorkerExit(ThreadPoolExecutor.java:988)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
In the crash report, I see more than 1000 threads (RefQueueWorker), this explains OOM. All threads are just waiting, here is the dump:
RefQueueWorker@org.apache.http.impl.conn.tsccm.ConnPoolByRoute@43b42098
at java.lang.Object.wait(Object.java)
at java.lang.Object.wait(Object.java:401)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:102)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:73)
at org.apache.http.impl.conn.tsccm.RefQueueWorker.run(RefQueueWorker.java:102)
at java.lang.Thread.run(Thread.java:841)
(...)
RefQueueWorker@org.apache.http.impl.conn.tsccm.ConnPoolByRoute@45f62f08
at java.lang.Object.wait(Object.java)
at java.lang.Object.wait(Object.java:401)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:102)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:73)
at org.apache.http.impl.conn.tsccm.RefQueueWorker.run(RefQueueWorker.java:102)
at java.lang.Thread.run(Thread.java:841)
Code used to get HttpClient:
public static HttpClient getHttpClient(Context context)
{
HttpClient httpClient = AndroidHttpClient.newInstance("appname", context);
HttpParams params = httpClient.getParams();
params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpConnectionParams.setConnectionTimeout(params, 5000);
HttpConnectionParams.setSoTimeout(params, 5000);
return httpClient;
}
Each request closes AndroidHttpClient in the finally block:
...
finally
{
if ((client instanceof AndroidHttpClient))
{
((AndroidHttpClient) client).close();
}
}
I can not reproduce this failure, it happened for only one user (Nexus 5 / API 4.4.2). I am wondering what could be the main reason for this insane amount of created thread?
thanks
source
share