Jetty的核心类
Server
ThreadPool(有两个实现),见这里http://lixjluck.iteye.com/blog/1129558
SelectChannelConnector
SelectorManager
SelectSet
SelectChannelEndPoint
HttpConnection(HttpInput, HttpOutput, HttpGenerator)
Handler
Server启动过程
SelectChannelConnector初始化过程
open方法做了什么事情?
public void open() throws IOException
{
synchronized(this)
{
if (_acceptChannel == null)
{
// Create a new server socket
_acceptChannel = ServerSocketChannel.open();
// Set to blocking mode
_acceptChannel.configureBlocking(true);
// Bind the server socket to the local host and port
_acceptChannel.socket().setReuseAddress(getReuseAddress());
InetSocketAddress addr = getHost()==null?new InetSocketAddress(getPort()):new InetSocketAddress(getHost(),getPort());
_acceptChannel.socket().bind(addr,getAcceptQueueSize());
_localPort=_acceptChannel.socket().getLocalPort();
if (_localPort<=0)
throw new IOException("Server channel not bound");
}
}
}
主要是启动web服务的监听端口,且配置成blocking模式。
Acceptor
acceptorThread的作用:
- Acceptor类 位于AbstractConnector.Acceptor
- 实际调用到SelectSet.doSelect
- Select and dispatch tasks found from changes and the selector
acceptor线程数量配置,见 http://lixjluck.iteye.com/blog/1129479 #acceptors |