惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Forbes - Security
Forbes - Security
T
Tailwind CSS Blog
Hugging Face - Blog
Hugging Face - Blog
Blog — PlanetScale
Blog — PlanetScale
WordPress大学
WordPress大学
aimingoo的专栏
aimingoo的专栏
Y
Y Combinator Blog
U
Unit 42
I
InfoQ
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
V
Visual Studio Blog
B
Blog RSS Feed
Vercel News
Vercel News
F
Fortinet All Blogs
Know Your Adversary
Know Your Adversary
T
Troy Hunt's Blog
博客园 - 【当耐特】
MongoDB | Blog
MongoDB | Blog
大猫的无限游戏
大猫的无限游戏
A
About on SuperTechFans
Jina AI
Jina AI
小众软件
小众软件
T
Threatpost
有赞技术团队
有赞技术团队
人人都是产品经理
人人都是产品经理
The Hacker News
The Hacker News
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Microsoft Azure Blog
Microsoft Azure Blog
Recent Announcements
Recent Announcements
酷 壳 – CoolShell
酷 壳 – CoolShell
Scott Helme
Scott Helme
B
Blog
腾讯CDC
Last Week in AI
Last Week in AI
P
Proofpoint News Feed
S
Schneier on Security
N
News and Events Feed by Topic
Microsoft Security Blog
Microsoft Security Blog
K
Kaspersky official blog
G
Google Developers Blog
T
Tor Project blog
PCI Perspectives
PCI Perspectives
S
Secure Thoughts
Google Online Security Blog
Google Online Security Blog
Latest news
Latest news
Google DeepMind News
Google DeepMind News
MyScale Blog
MyScale Blog
罗磊的独立博客

博客园 - sql172

好久没写了 Android自带混淆打包在windows下的一个问题 J2ME低级界面与高级界面切换的问题 cron启动失败 对自己无语了 今天又改了下数据源 ~ .... 今天去看了华尔街2 ClassNotFoundException 返宁 自定义大小数字绘制 十一 又废了一天 V8 JavaScript 引擎 分区表的问题 J2ME 混淆编译 J2ME的repaint效率问题
关于HTTP请求中断问题
sql172 · 2010-10-27 · via 博客园 - sql172

手机开发时侯,我们访问网络数据,经常因为各种原因会导致网络缓慢或者失去连接

这时候,由于HttpConnection.getResponseCode()请求是阻塞的,我们的程序一般是单独线程去请求数据,该线程就会永远的等在那,并且事后即使连上了,接收到的数据一般都已经是我们抛弃的了.此时我们很想在请求超时的时侯将这个阻塞的请求异步关闭它,但是这样是无法实现的.

一种方法是,我们直接用Connector.open的超时参数

另一种方法我们自己控制,在后面接收数据的时侯中断掉.

1 我们给HTTP请求线程封装上计时器

2 在接收数据时侯,避免一个大byte[]读完,而是while循环读取固定大小的块

3 在while读取数据时候,加入判断超时条件

这样一来,如果是已经过时的数据,我们即使接到请求相应了,但是我们不必去接收它的数据,一来节省资源,而来为用户节省流量.