Monday, February 17, 2014

About HTTP TCP connection issues


Today came across a very strange question, I use Android HttpClient obtain data through http requests, I used to get data Timer timer, and then after a while, I stopped the Timer is running, and then try to get a few other the same type of data that is accessed parameters changed a little, but always seemed to be blocked for some time, I use HttpCient is singleton pattern, if not singleton pattern does not happen, to ask, which is why ah, Android's official website there is no detailed explanation ah, which in the end is why ah<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Is not a httpclient only establish a TCP connection, but my singleton pattern used on other sites will not happen
Reply:
The use HttpClient once you stop Timer, but the network operator may not be able to stop immediately, so you feel there is a case delays.

HttpClient this single case is not recommended, especially in the case of multi-threaded under
Reply:
reference to the second floor birdsaction reply:
HttpClient the use once you stop Timer, but the network operator may not be able to stop immediately, so you feel there is a delay situation.

HttpClient this single case is not recommended, especially in the case of multi-threaded,
But one application is enough really an amazing httpclient Moreover httpclient supports multithreading, I think it is not because the synchronization The problem caused by obstruction
Reply:
Read the android SDK source code found in the Timer is in itself generates a Thread, and all operations are performed in this thread, but in the last disconnected when the main thread I made a "0" mark to server (method calls are the same). Then, I immediately (note the immediate restart, because this time, the thread has not yet been recovered) and then re-send the data on the back of Timer blocked this problem, I carefully explored and found each Timer will generate an execution Http thread to request, but this phenomenon is not blocked, the program is run properly. But when I set HttpClient does not support multi-thread-safe mechanism, the program would not have blocked this phenomenon, we know, is a result of multi-threading. . . But why does not cause obstruction Timer and Timer Interval time I connect that time, even shorter than I restart, I will continue to research

No comments:

Post a Comment