Jetty的核心

Jetty的核心类

Server

ThreadPool(有两个实现),见这里http://lixjluck.iteye.com/blog/1129558

SelectChannelConnector

SelectorManager

SelectSet

SelectChannelEndPoint

 

HttpConnection(HttpInput,  HttpOutput,  HttpGenerator)

Handler

 

 

Server启动过程

Jetty的核心_第1张图片
 SelectChannelConnector初始化过程

Jetty的核心_第2张图片

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

Jetty的核心_第3张图片

 

acceptorThread的作用:

 

  1. Acceptor类 位于AbstractConnector.Acceptor
  2. 实际调用到SelectSet.doSelect
  3. Select and dispatch tasks found from changes and the selector

 

 

acceptor线程数量配置,见 http://lixjluck.iteye.com/blog/1129479 #acceptors

 

 

你可能感兴趣的:(jetty)