Android (2.1) HttpGet.abort() 不起作用
我调用 abort() ,并且在execute() 中阻塞的线程不会解除阻塞,直到因异常而超时。可能需要 10 秒以上,所以这是一个大问题。
我环顾四周,找不到这个问题的答案。
文档说 abort() 应该导致阻塞 i/o 的execute() 立即解除阻塞。研究表明这个问题不久前已经得到解决。
当然,我从不同的线程调用 abort() 和execute()。我的代码没有什么特别的,所以我不会浪费空间列出它。
我发现一些帖子建议在 HttpClient 下搞乱套接字等,但这些都不起作用。
I call abort() and the thread that is blocking in execute() doesn't unblock until it times out with an exception. It can take over 10 seconds, so this is a big problem.
I've looked around for a while and I can't find the answer to this.
The docs say that abort() should cause the execute() blocking i/o to unblock immediately. Research suggests that this problem was fixed a while ago.
I am calling abort() and execute() from different threads, of course. There's nothing special about my code, so I won't waste space listing it.
Some posts I found suggested messing with the sockets and such underneath the HttpClient, but none of those worked either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否只是希望 HttpGet 在已知时间后超时,或者是否有理由必须尝试取消获取?我怀疑中止只有在有要读取的响应流之后才起作用......就像中止长下载一样。您可以尝试使用 URLConnection 而不是 HttpGet,它允许您独立设置读取和连接超时。
Are you just wanting HttpGet to timeout after a known amount of time, or is there a reason why you must try to cancel the get? I suspect that abort only works after it has a response stream to be reading...as in abort a long download. You might try using URLConnection instead of HttpGet which allows you to set read and connection timeouts independently.