Android程序在长时间休眠后HttpClient不工作 用bugreport看线程信息都是在await
ConnectTask #3" prio=5 tid=16 WAIT
| group="main" sCount=1 dsCount=0 obj=0x4055a0a8 self=0x335db0
| sysTid=10869 nice=10 sched=0/0 cgrp=default handle=3366632
| schedstat=( 97869859 8969970715 475 )
at java.lang.Object.wait(Native Method)
- waiting on <0x4055a220> (a java.lang.VMThread)
at java.lang.Thread.parkFor(Thread.java:1443)
at java.lang.LangAccessImpl.parkFor(LangAccessImpl.java:48)
at sun.misc.Unsafe.park(Unsafe.java:337)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:157)
at 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:555)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
at cn.com.fetion.connect.http.HttpHandler.executeHttpRequest(HttpHandler.java:157)
at cn.com.fetion.connect.http.AuthHttpHandler.doHttpGet(AuthHttpHandler.java:171)
at cn.com.fetion.connect.common.FetionConnectAPI.getCurrentStatusMessage(FetionConnectAPI.java:973)
at cn.com.fetion.connect.service.StatusMessageService$1.run(StatusMessageService.java:37)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:444)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
at java.lang.Thread.run(Thread.java:1027)
找到原因是再设置连接的时候的问题,在执行的时候Timeout是通过HttpRequest的HttpParams提供的。
程序在
client = new DefaultHttpClient(ccm, httpParams);
client.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,
TIMEOUT * 4000);
client.getParams().setParameter(
CoreConnectionPNames.CONNECTION_TIMEOUT, TIMEOUT * 1000);