项目 用了android 的AsyncTask 在频繁的请求的时候很容易阻塞 一个请求堵住就会导致这个接口一直挂无法连接 bug 复现随机性很强 非常变态。
在ddms里面看异步任务的线程 发现异常 (这真的找了好久。。。)
正常的asynctask
异常asynctask
at java.lang.Object.wait(Native Method)
at java.lang.Thread.parkFor(Thread.java:1231)
at sun.misc.Unsafe.park(Unsafe.java:323)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:159)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2019)
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:176)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:326)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
at com.fanli.android.http.FLHttpClient.httpRequest(FLHttpClient.java:628)
at com.fanli.android.http.FLHttpClient.httpRequest(FLHttpClient.java:555)
at com.fanli.android.http.FLHttpClient.httpRequest(FLHttpClient.java:549)
at com.fanli.android.http.FLHttpClient.post(FLHttpClient.java:507)
at com.fanli.android.io.FanliApi.getUpdateInfo(FanliApi.java:289)
at com.fanli.android.activity.MainTabActivity$GetXMLTask.getContent(MainTabActivity.java:735)
at com.fanli.android.activity.MainTabActivity$GetXMLTask.getContent(MainTabActivity.java:1)
at com.fanli.android.activity.task.FLGenericTask.doInBackground(FLGenericTask.java:58)
at com.fanli.android.activity.task.FLGenericTask.doInBackground(FLGenericTask.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)
复现过程:频繁用asynctask请求接口
bug症状:一直在loading 返回取消loading后 其他接口随机开始变卡
发现前某任程序员用了开源框架Afinal 做http(项目没文档没注释 原版开发人员又走了 感觉接手起来真特么恶心)
http://www.cnblogs.com/bvin/archive/2013/06/02.html 描述来看 是异步任务里面的网络请求模块有问题 遇到频繁请求时会卡住 然后拖住这个异步任务
有时间还要继续看一下这个问题
2014-2-20
android的异步任务在3.0以后改为串行 我们代码通过ThreadSafeClientConnManager确保线程安全,在由于我们http模块是一个httpclient的单例,httpclient阻塞又被锁住了,a整个app网络挂掉了