筆記:
1.等待接受連接配接:java.net.Socket socket = java.net.ServerSocket.accept()
2.處理連接配接:通過socket.getInputStream()把用戶端HTTP傳過來的資訊封裝成javax.servlet.http.HttpServletRequest對象
3.Tomcat4 的預設連接配接器httpConnector
隻負責擷取socket,給processor線程異步處理,馬上傳回以便下一個前來的 HTTP 請求可以被處理
// Hand this socket off to an appropriate 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 socket to processor " + processor);
processor.assign(socket);
這裡是 HttpProcessor 類的 assign 和 await 方法
synchronized void assign(Socket socket) {
// Wait for the Processor to get the previous Socket
while (available) {
try {
wait();
} catch (InterruptedException e) {
}
}
// Store the newly available Socket and notify our thread
this.socket = socket;
available = true;
notifyAll();
if ((debug >= 1) && (socket != null))
log(" An incoming request is being assigned");
}
/**
* Await a newly assigned Socket from our Connector, or <code>null</code>
* if we are supposed to shut down.
*/
private synchronized Socket await() {
// Wait for the Connector to provide a new Socket
while (!available) {
try {
wait();
} catch (InterruptedException e) {
}
}
// Notify the Connector that we have received this Socket
Socket socket = this.socket;
available = false;
notifyAll();
if ((debug >= 1) && (socket != null))
log(" The incoming request has been awaited");
return (socket);
}
轉載于:https://www.cnblogs.com/shapeOfMyHeart/p/5746482.html