Friday, April 18, 2014

Ask a question about blocking the thread termination


Thread, while (true) loop, accept or recieve listen, when the external network is disconnected, there is no way to terminate this thread?
I intend Service in judgment, after meeting the conditions to restart the Service themselves, because Service start threads, so Service stopped when the thread is also terminated. Are there any better way to stop the blocking thread? Because if not terminated, then the next start threads on the network connection, the port may be occupied. Memory because the thread is not to withdraw, but the more you use the more.
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
When marking off the network, and then thread the inside of the tag to make the judgment on off net return;
Reply:
When you start a multi-threaded, thread should be saved, and then after the break Netcom received knowledge, all of these thread interrupt (), interrupt just lift the socket blocking, not terminated, so you'll catch a interruptException, and in which, do some additional processing, then socket.close or close the current thread.
Reply:
Set mark inside the loop reads the tag
Also you are not the end of the thread end Service unless you end the whole process
Reply:
@ Tanwei4199, ending Service and Activty I just test it really is not the end of the thread, and some textbooks written Acitivety which direct the calling thread is not recommended, because the interface may be out of the thread has not yet finished, it seems this is the text description wrong.
Interrupt thread seems only two ways, first set the variable, the second is blocked unable to determine if the use of variable interrupt (). This understanding correct?

No comments:

Post a Comment