我们从启动流程图上可以了解到,当standardWrapper启动完成之后,那么返回到standardService的start方法里边时,会执行HttpConnector的start方法:
HttpConnector的start方法源码:
public void start() throwsLifecycleException {
// Validate and update our current state
if (started)
throw new LifecycleException
(sm.getString("httpConnector.alreadyStarted"));
threadName = "HttpConnector[" + port + "]";
lifecycle.fireLifecycleEvent(START_EVENT, null);
started = true;
// Start our background thread
threadStart();
// Create the specified minimum number of processors
while (curProcessors < minProcessors) {
if ((maxProcessors > 0) && (curProcessors >=maxProcessors))
break;
HttpProcessor processor = newProcessor();
recycle(processor);
}
}
因HttpConnector实现了Runnable接口,十一这个了出现threadStart:
private voidthreadStart() {
log(sm.getString("httpConnector.starting"));
thread = new Thread(this, threadName);
thread.setDaemon(true);
thread.start();
}
调用了线程的run方法:
public voidrun() {
// Loop until we receive a shutdowncommand
while (!stopped) {
// Accept the next incomingconnection from the server socket
Socket socket = null;
try {
// if (debug >= 3)
// log("run: Waiting onserverSocket.accept()");
socket = serverSocket.accept();
// if (debug >= 3)
// log("run: Returnedfrom serverSocket.accept()");
if (connectionTimeout > 0)
socket.setSoTimeout(connectionTimeout);
socket.setTcpNoDelay(tcpNoDelay);
} catch (AccessControlExceptionace) {
log("socket acceptsecurity exception", ace);
continue;
} catch (IOException e) {
// if (debug >= 3)
// log("run: Acceptreturned IOException", e);
try {
// If reopening fails, exit
synchronized (threadSync) {
if (started &&!stopped)
log("accepterror: ", e);
if (!stopped) {
// if (debug >= 3)
// log("run: Closing server socket");
serverSocket.close();
// if (debug >= 3)
// log("run:Reopening server socket");
serverSocket = open();
}
}
// if (debug >= 3)
// log("run:IOException processing completed");
} catch (IOException ioe) {
log("socket reopen, ioproblem: ", ioe);
break;
} catch (KeyStoreException kse){
log("socket reopen,keystore problem: ", kse);
break;
} catch(NoSuchAlgorithmException nsae) {
log("socket reopen,keystore algorithm problem: ", nsae);
break;
} catch (CertificateExceptionce) {
log("socket reopen,certificate problem: ", ce);
break;
} catch(UnrecoverableKeyException uke) {
log("socket reopen,unrecoverable key: ", uke);
break;
} catch (KeyManagementException kme) {
log("socket reopen,key management problem: ", kme);
break;
}
continue;
}
// Hand this socket off to anappropriate processor
HttpProcessor processor =createProcessor();
if (processor == null) {
try {
log(sm.getString("httpConnector.noProcessor"));
socket.close();
} catch (IOException e) {
;
}
continue;
}
// if (debug >= 3)
// log("run: Assigning socketto processor " + processor);
processor.assign(socket);
// The processor will recycleitself when it finishes
}
// Notify the threadStop() method thatwe have shut ourselves down
// if (debug >= 3)
// log("run: NotifyingthreadStop() that we have shut down");
synchronized (threadSync) {
threadSync.notifyAll();
}
}
从源码上我们可以知道这里采用了一个while循环,知道stop指令下达之后才会停止,否则一直循环等待,直到serverSocket.accept接收到请求之后,程序才会往下执行!我们才会开始下一章节的请求
HttpConnector的启动的关系类图: