如何从异常跟踪堆栈中分辨出连接超时和套接字超时?

时间:2011-08-22 18:52:44

标签: java android

我在程序中使用了apache http client lib。我为网络调用设置了连接超时和套接字超时。我的理解是,如果有连接超时,客户端没有到达后端服务器;如果存在套接字超时,则客户端到达后端服务器但服务器没有响应或非常慢。

我记录以下异常跟踪堆栈。如何判断哪个超时(连接或套接字)导致异常?谢谢!

java.net.SocketException: The operation timed out
at org.apache.harmony.luni.platform.OSNetworkSystem.connectStreamWithTimeoutSocketImpl(NativeMethod)
at org.apache.harmony.luni.platform.OSNetworkSystem.connectStreamWithTimeoutSocket(OSNetworkSystem.java:130)
at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:247)
at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:534)
at java.net.Socket.connect(Socket.java:1056)
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:348)
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)

1 个答案:

答案 0 :(得分:1)

从堆栈跟踪中,您可以告诉它在尝试establish the connection时超时,而不是在尝试从Socket's InputStream读取时。