public synchronized boolean stop() {
close();
bHttpServerThreadFlag = false;
DLog.i(mTAG, "stop", "Wait start for finishing thread !!!");
if (mHttpServerThread != null && mHttpServerThread.isAlive()) {
try {
mHttpServerThread.join();
} catch (InterruptedException e) {
DLog.w(mTAG, "stop", "Thread Join InterruptedException", e);
}
}
DLog.i(mTAG, "stop", "Wait done for finishing thread !!!");
mHttpServerThread = null;
// CTT 2.0
// Accepted socket SHOULD be closed
synchronized (mAcceptSocketList) {
for (WeakReference
sockRef : mAcceptSocketList) {
try {
Socket sock = sockRef.get();
if (sock != null) {
sock.close();
}
} catch (IOException e) {
DLog.w(mTAG, "stop", "Error: socket - IOException", e);
}
}
mAcceptSocketList.clear();
}
return true;
}
6.服务线程的关闭
public boolean close() {
if (mServerSock == null)
return true;
try {
mServerSock.close();
} catch (Exception e) {
DLog.w(mTAG, "open", "Close - Exception :", e);
return false;
} finally {
mServerSock = null;
mBindPort = 0;
}
return true;
}