views:

21

answers:

0

I use an httpconnection to post some data to the server and wait for response.

The connection can be canceled by closing the inputstream, outputstream and connection.

But if I cancel the connection at a right timing, then though the is, os, connnection are closed, but the worker thread just hand there, for about one minute. And then a nullpointer will be thrown out.

Actually I encountered this kind of problem, but rearrange the order of the close fix the problem. But now it can not work no matter in what order I close the inputstream, outputstream, connection.

Is someone else encounter this problem? All the network related job is in worker thread instead of ui thread.

Below is the stacktrace in the hand thread while handing there.

Thread [<17> Worker Threads-0] (Suspended)
OSNetworkSystem.receiveStreamImpl(FileDescriptor, byte[], int, int, int) line: not available [native method]
OSNetworkSystem.receiveStream(FileDescriptor, byte[], int, int, int) line: 236
PlainSocketImpl2(PlainSocketImpl).read(byte[], int, int) line: 550
SocketInputStream.read() line: 61
HttpURLConnection.readln() line: 1181
HttpURLConnection.readServerResponse() line: 1253
HttpURLConnection.sendRequest() line: 1241
HttpURLConnection.doRequestInternal() line: 1554
HttpURLConnection.doRequest() line: 1547
HttpURLConnection.getOutputStream() line: 1148
AndroidHttpServerConnection.getOutputStream() line: 81
AndroidHttpServerConnection(ServerConnection).send(byte[][]) line: 59
ServiceCallImpl.invoke() line: 149
AsynchronousServiceCallInvoker$1.run() line: 43 Worker.run() line: 213