Search in sources :

Example 41 with QueuedThreadPool

use of org.eclipse.jetty.util.thread.QueuedThreadPool in project jetty.project by eclipse.

the class ProxyServletFailureTest method prepareServer.

private void prepareServer(HttpServlet servlet) throws Exception {
    QueuedThreadPool executor = new QueuedThreadPool();
    executor.setName("server");
    server = new Server(executor);
    serverConnector = new ServerConnector(server);
    server.addConnector(serverConnector);
    ServletContextHandler appCtx = new ServletContextHandler(server, "/", true, false);
    ServletHolder appServletHolder = new ServletHolder(servlet);
    appCtx.addServlet(appServletHolder, "/*");
    server.start();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 42 with QueuedThreadPool

use of org.eclipse.jetty.util.thread.QueuedThreadPool in project jetty.project by eclipse.

the class InsufficientThreadsDetectionTest method testConnectorUsesServerExecutorWithNotEnoughThreads.

@Test(expected = IllegalStateException.class)
public void testConnectorUsesServerExecutorWithNotEnoughThreads() throws Exception {
    // server has 3 threads in the executor
    _server = new Server(new QueuedThreadPool(3));
    // connector will use executor from server because connectorPool is null
    ThreadPool connectorPool = null;
    // connector requires 7 threads(2 + 4 + 1)
    ServerConnector connector = new ServerConnector(_server, connectorPool, null, null, 2, 4, new HttpConnectionFactory());
    connector.setPort(0);
    _server.addConnector(connector);
    // should throw IllegalStateException because there are no required threads in server pool
    _server.start();
}
Also used : QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ThreadPool(org.eclipse.jetty.util.thread.ThreadPool) Test(org.junit.Test)

Example 43 with QueuedThreadPool

use of org.eclipse.jetty.util.thread.QueuedThreadPool in project jetty.project by eclipse.

the class InsufficientThreadsDetectionTest method testConnectorWithDedicatedExecutor.

@Test
public void testConnectorWithDedicatedExecutor() throws Exception {
    // server has 3 threads in the executor
    _server = new Server(new QueuedThreadPool(3));
    // connector pool has 100 threads
    ThreadPool connectorPool = new QueuedThreadPool(100);
    // connector requires 7 threads(2 + 4 + 1)
    ServerConnector connector = new ServerConnector(_server, connectorPool, null, null, 2, 4, new HttpConnectionFactory());
    connector.setPort(0);
    _server.addConnector(connector);
    // should not throw exception because connector uses own executor, so its threads should not be counted
    _server.start();
}
Also used : QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ThreadPool(org.eclipse.jetty.util.thread.ThreadPool) Test(org.junit.Test)

Example 44 with QueuedThreadPool

use of org.eclipse.jetty.util.thread.QueuedThreadPool in project jetty.project by eclipse.

the class InsufficientThreadsDetectionTest method testCaseForMultipleConnectors.

// Github issue #586
@Test
public void testCaseForMultipleConnectors() throws Exception {
    // server has 4 threads in the executor
    _server = new Server(new QueuedThreadPool(4));
    // first connector consumes all 4 threads from server pool
    _server.addConnector(new ServerConnector(_server, null, null, null, 1, 1, new HttpConnectionFactory()));
    // second connect also require 4 threads but uses own executor, so its threads should not be counted
    final QueuedThreadPool connectorPool = new QueuedThreadPool(4, 4);
    _server.addConnector(new ServerConnector(_server, connectorPool, null, null, 1, 1, new HttpConnectionFactory()));
    // should not throw exception because limit was not overflown
    _server.start();
}
Also used : QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) Test(org.junit.Test)

Example 45 with QueuedThreadPool

use of org.eclipse.jetty.util.thread.QueuedThreadPool in project jetty.project by eclipse.

the class LowResourcesMonitorTest method before.

@Before
public void before() throws Exception {
    _threadPool = new QueuedThreadPool();
    _threadPool.setMaxThreads(50);
    _server = new Server(_threadPool);
    _server.manage(_threadPool);
    _server.addBean(new TimerScheduler());
    _connector = new ServerConnector(_server);
    _connector.setPort(0);
    _connector.setIdleTimeout(35000);
    _server.addConnector(_connector);
    _server.setHandler(new DumpHandler());
    _lowResourcesMonitor = new LowResourceMonitor(_server);
    _lowResourcesMonitor.setLowResourcesIdleTimeout(200);
    _lowResourcesMonitor.setMaxConnections(20);
    _lowResourcesMonitor.setPeriod(900);
    _server.addBean(_lowResourcesMonitor);
    _server.start();
}
Also used : TimerScheduler(org.eclipse.jetty.util.thread.TimerScheduler) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) Before(org.junit.Before)

Aggregations

QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)126 Server (org.eclipse.jetty.server.Server)65 ServerConnector (org.eclipse.jetty.server.ServerConnector)51 Test (org.junit.Test)30 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)26 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)23 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)22 HttpClient (org.eclipse.jetty.client.HttpClient)18 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)18 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)18 IOException (java.io.IOException)17 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)11 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)11 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)10 File (java.io.File)9 CountDownLatch (java.util.concurrent.CountDownLatch)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 InputStream (java.io.InputStream)8 HttpServletResponse (javax.servlet.http.HttpServletResponse)8 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)8