Search in sources :

Example 1 with SizedThreadPool

use of org.eclipse.jetty.util.thread.ThreadPool.SizedThreadPool in project jetty.project by eclipse.

the class Server method doStart.

/* ------------------------------------------------------------ */
@Override
protected void doStart() throws Exception {
    // Create an error handler if there is none
    if (_errorHandler == null)
        _errorHandler = getBean(ErrorHandler.class);
    if (_errorHandler == null)
        setErrorHandler(new ErrorHandler());
    if (_errorHandler instanceof ErrorHandler.ErrorPageMapper)
        LOG.warn("ErrorPageMapper not supported for Server level Error Handling");
    //with the shutdown handler thread.
    if (getStopAtShutdown())
        ShutdownThread.register(this);
    //Register the Server with the handler thread for receiving
    //remote stop commands
    ShutdownMonitor.register(this);
    //Start a thread waiting to receive "stop" commands.
    // initialize
    ShutdownMonitor.getInstance().start();
    LOG.info("jetty-" + getVersion());
    if (!Jetty.STABLE) {
        LOG.warn("THIS IS NOT A STABLE RELEASE! DO NOT USE IN PRODUCTION!");
        LOG.warn("Download a stable release from http://download.eclipse.org/jetty/");
    }
    HttpGenerator.setJettyVersion(HttpConfiguration.SERVER_VERSION);
    // Check that the thread pool size is enough.
    SizedThreadPool pool = getBean(SizedThreadPool.class);
    int max = pool == null ? -1 : pool.getMaxThreads();
    int selectors = 0;
    int acceptors = 0;
    for (Connector connector : _connectors) {
        if (connector instanceof AbstractConnector) {
            AbstractConnector abstractConnector = (AbstractConnector) connector;
            Executor connectorExecutor = connector.getExecutor();
            if (connectorExecutor != pool) {
                // the server level, because the connector uses a dedicated executor.
                continue;
            }
            acceptors += abstractConnector.getAcceptors();
            if (connector instanceof ServerConnector) {
                // The SelectorManager uses 2 threads for each selector,
                // one for the normal and one for the low priority strategies.
                selectors += 2 * ((ServerConnector) connector).getSelectorManager().getSelectorCount();
            }
        }
    }
    int needed = 1 + selectors + acceptors;
    if (max > 0 && needed > max)
        throw new IllegalStateException(String.format("Insufficient threads: max=%d < needed(acceptors=%d + selectors=%d + request=1)", max, acceptors, selectors));
    MultiException mex = new MultiException();
    try {
        super.doStart();
    } catch (Throwable e) {
        mex.add(e);
    }
    // start connectors last
    for (Connector connector : _connectors) {
        try {
            connector.start();
        } catch (Throwable e) {
            mex.add(e);
        }
    }
    if (isDumpAfterStart())
        dumpStdErr();
    mex.ifExceptionThrow();
    LOG.info(String.format("Started @%dms", Uptime.getUptime()));
}
Also used : ErrorHandler(org.eclipse.jetty.server.handler.ErrorHandler) Executor(java.util.concurrent.Executor) MultiException(org.eclipse.jetty.util.MultiException) SizedThreadPool(org.eclipse.jetty.util.thread.ThreadPool.SizedThreadPool)

Aggregations

Executor (java.util.concurrent.Executor)1 ErrorHandler (org.eclipse.jetty.server.handler.ErrorHandler)1 MultiException (org.eclipse.jetty.util.MultiException)1 SizedThreadPool (org.eclipse.jetty.util.thread.ThreadPool.SizedThreadPool)1