欢迎来到天天文库
浏览记录
ID:12350356
大小:59.00 KB
页数:8页
时间:2018-07-16
《http线程阻塞分析》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、先做一个总结:Http连接线程发生阻塞,会影响其他线程也出现阻塞状况。修正:这种状况只会出现在emulator中,在真机中一切正常,不会出现"其他线程也出现阻塞状况"。Http连接线程发生阻塞时,HttpConnection对象已在Native中运行,TimerTask线程中的close()也会阻塞,所以如果某个HttpConnection线程阻塞了,你就抛弃这个线程好了(没必要强行interrupt或者close),让它自生自灭,再重开一个线程重新进行连接好了。ps:手机中测试(1)在Form中显示信息;(2)Log。我认为这是j2me的一个bug
2、。下面是代码:3、20throws%20MIDletStateChangeException%20%7B%0A%09Timer%20timer%20%3D%20new%20Timer()%3B%0A%09timer.schedule(netTimerTask%2C%202000)%3B%0A%09new%20Thread()%20%7B%0A%09%09public%20void%20run()%20%7B%0A%09%09%09try%20%7B%0A%09%09%09%09conn%20%3D%20(HttpConnection)%20Connector.open4、(%22http%3A%2F%2F10.0.0.172%3A80%22%2C%20Connector.READ_WRITE%2C%20true)%3B%0A%09%09%09%09conn.setRequestProperty(%22X-Online-Host%22%2C%20%22wap.sina.com%22)%3B%0A%09%09%09%09responseCode%20%3D%20conn.getResponseCode()%3B%0A%09%09%09%09if%20(responseCode%20%3D%3D%20HttpConnect5、ion.HTTP_OK)%20%7B%0A%2F%2F%09%09%09%09%09LogManager.info(%22Wap%20Pass%20Code%20%3D%20%22%20%2B%20responseCode)%3B%0A%09%09%09%09%09System.out.println(%22Wap%20Pass%20Code%20%3D%20%22%20%2B%20responseCode)%3B%0A%09%09%09%09%7D%20else%20%7B%0A%2F%2F%09%09%09%09%09LogManager.inf6、o(%22Wap%20Fail%20Code%20%3D%20%22%20%2B%20responseCode)%3B%0A%09%09%09%09%09System.out.println(%22Wap%20Fail%20Code%20%3D%20%22%20%2B%20responseCode)%3B%0A%09%09%09%09%7D%0A%09%09%09%7D%20catch%20(IOException%20e)%20%7B%0A%09%09%09%09try%20%7B%0A%09%09%09%09%09conn%20%3D%20(Ht7、tpConnection)%20Connector.open(%22http%3A%2F%2Fwap.sina.com%22%2C%20Connector.READ_WRITE%2C%20true)%3B%0A%09%09%09%09%09responseCode%20%3D%20conn.getResponseCode()%3B%0A%09%09%09%09%09if%20(responseCode%20%3D%3D%20HttpConnection.HTTP_OK)%20%7B%0A%2F%2F%09%09%09%09%09%09LogManag8、er.info(%22Net%20Pass%20Code%20%3D%20%22%20%2B%20respo
3、20throws%20MIDletStateChangeException%20%7B%0A%09Timer%20timer%20%3D%20new%20Timer()%3B%0A%09timer.schedule(netTimerTask%2C%202000)%3B%0A%09new%20Thread()%20%7B%0A%09%09public%20void%20run()%20%7B%0A%09%09%09try%20%7B%0A%09%09%09%09conn%20%3D%20(HttpConnection)%20Connector.open
4、(%22http%3A%2F%2F10.0.0.172%3A80%22%2C%20Connector.READ_WRITE%2C%20true)%3B%0A%09%09%09%09conn.setRequestProperty(%22X-Online-Host%22%2C%20%22wap.sina.com%22)%3B%0A%09%09%09%09responseCode%20%3D%20conn.getResponseCode()%3B%0A%09%09%09%09if%20(responseCode%20%3D%3D%20HttpConnect
5、ion.HTTP_OK)%20%7B%0A%2F%2F%09%09%09%09%09LogManager.info(%22Wap%20Pass%20Code%20%3D%20%22%20%2B%20responseCode)%3B%0A%09%09%09%09%09System.out.println(%22Wap%20Pass%20Code%20%3D%20%22%20%2B%20responseCode)%3B%0A%09%09%09%09%7D%20else%20%7B%0A%2F%2F%09%09%09%09%09LogManager.inf
6、o(%22Wap%20Fail%20Code%20%3D%20%22%20%2B%20responseCode)%3B%0A%09%09%09%09%09System.out.println(%22Wap%20Fail%20Code%20%3D%20%22%20%2B%20responseCode)%3B%0A%09%09%09%09%7D%0A%09%09%09%7D%20catch%20(IOException%20e)%20%7B%0A%09%09%09%09try%20%7B%0A%09%09%09%09%09conn%20%3D%20(Ht
7、tpConnection)%20Connector.open(%22http%3A%2F%2Fwap.sina.com%22%2C%20Connector.READ_WRITE%2C%20true)%3B%0A%09%09%09%09%09responseCode%20%3D%20conn.getResponseCode()%3B%0A%09%09%09%09%09if%20(responseCode%20%3D%3D%20HttpConnection.HTTP_OK)%20%7B%0A%2F%2F%09%09%09%09%09%09LogManag
8、er.info(%22Net%20Pass%20Code%20%3D%20%22%20%2B%20respo
此文档下载收益归作者所有