Java Code Examples for org.eclipse.jetty.server.Server#getThreadPool()

The following examples show how to use org.eclipse.jetty.server.Server#getThreadPool() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractService.java    From ja-micro with Apache License 2.0 6 votes vote down vote up
public void startJettyContainer() throws Exception {
    jettyServer = new Server(serviceProperties.getServicePort());
    org.eclipse.jetty.util.thread.ThreadPool threadPool = jettyServer.getThreadPool();
    if (threadPool instanceof QueuedThreadPool) {
        ((QueuedThreadPool) threadPool).setMaxThreads(FeatureFlags.getMaxJettyThreads(serviceProperties));
        ((QueuedThreadPool) threadPool).setMinThreads(FeatureFlags.getMinJettyThreads(serviceProperties));
    } else {
        logger.warn("Expected ThreadPool to be instance of QueuedThreadPool, but was {}",
                jettyServer.getThreadPool().getClass().getName());
    }
    JettyComposer.compose(jettyServer);
    jettyServer.start();
    int port = ((ServerConnector) jettyServer.getConnectors()[0]).getLocalPort();
    logger.info("Jetty has started on port {}", port);
    serviceProperties.setServicePort(port);
}
 
Example 2
Source File: AthenzJettyContainerTest.java    From athenz with Apache License 2.0 6 votes vote down vote up
@Test
public void testContainerThreadPool() {
    
    System.setProperty(AthenzConsts.ATHENZ_PROP_MAX_THREADS, "100");
    
    AthenzJettyContainer container = new AthenzJettyContainer();
    container.createServer(100);
    
    Server server = container.getServer();
    assertNotNull(server);
    
    ThreadPool threadPool = server.getThreadPool();
    assertNotNull(threadPool);
    
    // at this point we have no threads so the value is 0
    assertEquals(threadPool.getThreads(), 0);
    assertEquals(threadPool.getIdleThreads(), 0);
}
 
Example 3
Source File: EmissaryServerIT.java    From emissary with Apache License 2.0 5 votes vote down vote up
@Test
public void testThreadPoolStuff() throws Exception {
    ServerCommand cmd = ServerCommand.parse(ServerCommand.class, "-h", "host1", "-p", "3001");
    EmissaryServer server = new EmissaryServer(cmd);
    Server jettyServer = server.configureServer();
    QueuedThreadPool pool = (QueuedThreadPool) jettyServer.getThreadPool();
    assertThat(pool.getMinThreads(), equalTo(10));
    assertThat(pool.getMaxThreads(), equalTo(250));
    assertThat(pool.getLowThreadsThreshold(), equalTo(50));
    assertThat(pool.getIdleTimeout(), equalTo(new Long(TimeUnit.MINUTES.toMillis(15)).intValue()));
    assertThat(pool.getThreadsPriority(), equalTo(9));
}