當前位置: 首頁>>代碼示例>>Java>>正文


Java QueuedThreadPool類代碼示例

本文整理匯總了Java中org.eclipse.jetty.util.thread.QueuedThreadPool的典型用法代碼示例。如果您正苦於以下問題:Java QueuedThreadPool類的具體用法?Java QueuedThreadPool怎麽用?Java QueuedThreadPool使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


QueuedThreadPool類屬於org.eclipse.jetty.util.thread包,在下文中一共展示了QueuedThreadPool類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: startInJvmProxy

import org.eclipse.jetty.util.thread.QueuedThreadPool; //導入依賴的package包/類
/**
 * To test that the CF client is able to go through a proxy, we point the CC client to a broken url that can only be resolved by going
 * through an inJVM proxy which rewrites the URI. This method starts this inJvm proxy.
 *
 * @throws Exception
 */
private static void startInJvmProxy() throws Exception {
    inJvmProxyPort = getNextAvailablePort(8080);
    inJvmProxyServer = new Server(new InetSocketAddress("127.0.0.1", inJvmProxyPort)); // forcing use of loopback
    // that will be used both for Httpclient proxy and SocketDestHelper
    QueuedThreadPool threadPool = new QueuedThreadPool();
    threadPool.setMinThreads(1);
    inJvmProxyServer.setThreadPool(threadPool);

    HandlerCollection handlers = new HandlerCollection();
    inJvmProxyServer.setHandler(handlers);

    ServletHandler servletHandler = new ServletHandler();
    handlers.addHandler(servletHandler);
    nbInJvmProxyRcvReqs = new AtomicInteger();
    ChainedProxyServlet chainedProxyServlet = new ChainedProxyServlet(httpProxyConfiguration, nbInJvmProxyRcvReqs);
    servletHandler.addServletWithMapping(new ServletHolder(chainedProxyServlet), "/*");

    // Setup proxy handler to handle CONNECT methods
    ConnectHandler proxyHandler;
    proxyHandler = new ChainedProxyConnectHandler(httpProxyConfiguration, nbInJvmProxyRcvReqs);
    handlers.addHandler(proxyHandler);

    inJvmProxyServer.start();
}
 
開發者ID:SAP,項目名稱:cf-java-client-sap,代碼行數:31,代碼來源:CloudFoundryClientTest.java

示例2: startJetty

import org.eclipse.jetty.util.thread.QueuedThreadPool; //導入依賴的package包/類
private void startJetty() throws Exception {
	QueuedThreadPool jettyThreadPool = new QueuedThreadPool(jettyServerThreads);
	Server server = new Server(jettyThreadPool);

	ServerConnector http = new ServerConnector(server, new HttpConnectionFactory());
	http.setPort(jettyListenPort);
	
	server.addConnector(http);
	
	ContextHandler contextHandler = new ContextHandler();
	contextHandler.setHandler(botSocketHandler);
	server.setHandler(contextHandler);
	
   	server.start();
   	server.join();
}
 
開發者ID:BuaBook,項目名稱:buabook-api-interface,代碼行數:17,代碼來源:BuaBookApiInterface.java

示例3: LegacyHttpServer

import org.eclipse.jetty.util.thread.QueuedThreadPool; //導入依賴的package包/類
private LegacyHttpServer(int port, int threads) {
  this.server = new Server(new QueuedThreadPool(threads));
  server.setHandler(
      new AbstractHandler() {
        @Override
        public void handle(
            String target,
            Request baseRequest,
            HttpServletRequest request,
            HttpServletResponse response)
            throws IOException {
          final String method = baseRequest.getParameter("method");
          if ("helloworld.Greeter/SayHello".equals(method)) {
            baseRequest.setHandled(true);
            sayHello(baseRequest, response);
          }
        }
      });

  final ServerConnector connector = new ServerConnector(server);
  connector.setPort(port);
  server.addConnector(connector);
}
 
開發者ID:codahale,項目名稱:grpc-proxy,代碼行數:24,代碼來源:LegacyHttpServer.java

示例4: createThreadPool

import org.eclipse.jetty.util.thread.QueuedThreadPool; //導入依賴的package包/類
/**
 * Creates a new thread pool for the server and hooks it's properties to the configuration events
 *
 * @return a new thread pool
 */
private static QueuedThreadPool createThreadPool() {

    final QueuedThreadPool threadPool = new QueuedThreadPool();
    threadPool.setMinThreads(Configuration.getInteger("jetty.threads.min", 10));
    threadPool.setMaxThreads(Configuration.getInteger("jetty.threads.max", 80));
    Configuration.addListener(ConfigChangeListener.forConfigProperty("jetty.threads.min", (k, v) -> {
        threadPool.setMinThreads(Integer.parseInt(v));
        restartThreadPool(threadPool);
        LOG.info("Successfully resized threadpool " + k + "=" + v);
    }));
    Configuration.addListener(ConfigChangeListener.forConfigProperty("jetty.threads.max", (k, v) -> {
        threadPool.setMaxThreads(Integer.parseInt(v));
        restartThreadPool(threadPool);
        LOG.info("Successfully resized threadpool " + k + "=" + v);
    }));
    return threadPool;
}
 
開發者ID:gmuecke,項目名稱:boutique-de-jus,代碼行數:23,代碼來源:BoutiqueDeJusWebServer.java

示例5: initHttpServer

import org.eclipse.jetty.util.thread.QueuedThreadPool; //導入依賴的package包/類
private void initHttpServer(final CoreConfigure cfg) {

        // 如果IP:PORT已經被占用,則無法繼續被綁定
        // 這裏說明下為什麽要這麽無聊加個這個判斷,讓Jetty的Server.bind()拋出異常不是更好麽?
        // 比較鬱悶的是,如果這個端口的綁定是"SO_REUSEADDR"端口可重用的模式,那麽這個server是能正常啟動,但無法正常工作的
        // 所以這裏必須先主動檢查一次端口占用情況,當然了,這裏也會存在一定的並發問題,BUT,我認為這種概率事件我可以選擇暫時忽略
        if (NetworkUtils.isPortInUsing(cfg.getServerIp(), cfg.getServerPort())) {
            throw new IllegalStateException(String.format("server[ip=%s;port=%s;] already in using, server bind failed.",
                    cfg.getServerIp(), cfg.getServerPort()));
        }

        httpServer = new Server(new InetSocketAddress(cfg.getServerIp(), cfg.getServerPort()));
        if (httpServer.getThreadPool() instanceof QueuedThreadPool) {
            final QueuedThreadPool qtp = (QueuedThreadPool) httpServer.getThreadPool();
            qtp.setName("sandbox-jetty-qtp" + qtp.hashCode());
        }
    }
 
開發者ID:alibaba,項目名稱:jvm-sandbox,代碼行數:18,代碼來源:JettyCoreServer.java

示例6: PrometheusExporter

import org.eclipse.jetty.util.thread.QueuedThreadPool; //導入依賴的package包/類
public PrometheusExporter(int port, String path) {
    
    QueuedThreadPool threadPool = new QueuedThreadPool(25);
    server = new Server(threadPool);

    ServerConnector connector = new ServerConnector(server);
    connector.setPort(port);
    server.addConnector(connector);

    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    server.setHandler(context);

    CollectorRegistry collectorRegistry = new CollectorRegistry();
    
    collectorRegistry.register(new PrometheusExports(CassandraMetricsRegistry.Metrics));

    MetricsServlet metricsServlet = new MetricsServlet(collectorRegistry);

    context.addServlet(new ServletHolder(metricsServlet), "/" + path);
    try {
        server.start();
    } catch (Exception e) {
        System.err.println("cannot start metrics http server " + e.getMessage());
    }
}
 
開發者ID:nabto,項目名稱:cassandra-prometheus,代碼行數:27,代碼來源:PrometheusExporter.java

示例7: JettyServer

import org.eclipse.jetty.util.thread.QueuedThreadPool; //導入依賴的package包/類
public JettyServer(final NiFiRegistryProperties properties, final CryptoKeyProvider cryptoKeyProvider) {
    final QueuedThreadPool threadPool = new QueuedThreadPool(properties.getWebThreads());
    threadPool.setName("NiFi Registry Web Server");

    this.properties = properties;
    this.masterKeyProvider = cryptoKeyProvider;
    this.server = new Server(threadPool);

    // enable the annotation based configuration to ensure the jsp container is initialized properly
    final Configuration.ClassList classlist = Configuration.ClassList.setServerDefault(server);
    classlist.addBefore(JettyWebXmlConfiguration.class.getName(), AnnotationConfiguration.class.getName());

    try {
        configureConnectors();
        loadWars();
    } catch (final Throwable t) {
        startUpFailure(t);
    }
}
 
開發者ID:apache,項目名稱:nifi-registry,代碼行數:20,代碼來源:JettyServer.java

示例8: jettyEmbeddedServletContainerFactory

import org.eclipse.jetty.util.thread.QueuedThreadPool; //導入依賴的package包/類
/**
 * Configures the embedded jetty server. The values are configured in
 * <b>application.yaml</b> file.
 *
 * @param port        jetty server port
 * @param maxThreads  thread pool min thread
 * @param minThreads  thread pool max thread
 * @param idleTimeout maximum thread idle time
 * @param jmxEnabled  true, if jetty jmx is enabled.
 * @return {@link JettyEmbeddedServletContainerFactory}
 */
@Bean
public JettyEmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory(@Value("${server.port:8443}") final int port,
                                                                                 @Value("${jetty.thread-pool.max-threads:200}") final int maxThreads,
                                                                                 @Value("${jetty.thread-pool.min-threads:8}") final int minThreads,
                                                                                 @Value("${jetty.thread-pool.idle-timeout:60000}") final int idleTimeout,
                                                                                 @Value("${jetty.jmx.enabled:true}") final boolean jmxEnabled) {
    log.info("Configuring Jetty server.");
    final JettyEmbeddedServletContainerFactory factory = new JettyEmbeddedServletContainerFactory(port);
    factory.addServerCustomizers(server -> {
        final QueuedThreadPool threadPool = server.getBean(QueuedThreadPool.class);
        threadPool.setMinThreads(minThreads);
        threadPool.setMaxThreads(maxThreads);
        threadPool.setIdleTimeout(idleTimeout);
        log.info("Server thread pool config:  " + server.getThreadPool());
        // Jetty JMX config.
        if (jmxEnabled) {
            log.info("Exposing Jetty managed beans to the JMX platform server.");
            server.addBean(new MBeanContainer(ManagementFactory.getPlatformMBeanServer()));
        }
    });
    return factory;
}
 
開發者ID:oneops,項目名稱:secrets-proxy,代碼行數:34,代碼來源:EmbeddedServerConfig.java

示例9: start

import org.eclipse.jetty.util.thread.QueuedThreadPool; //導入依賴的package包/類
public void start() throws Exception {
    if (server != null) throw new IllegalStateException("started");
    Scheduler.Config config = Scheduler.$.config;

    QueuedThreadPool threadPool = new QueuedThreadPool(Runtime.getRuntime().availableProcessors() * 16);
    threadPool.setName("Jetty");

    server = new Server(threadPool);
    ServerConnector connector = new ServerConnector(server);
    connector.setPort(config.apiPort());
    connector.setIdleTimeout(60 * 1000);

    ServletContextHandler handler = new ServletContextHandler();
    handler.addServlet(new ServletHolder(new Servlet()), "/");
    handler.setErrorHandler(new ErrorHandler());

    server.setHandler(handler);
    server.addConnector(connector);
    server.start();

    logger.info("started on port " + connector.getLocalPort());
}
 
開發者ID:elodina,項目名稱:hdfs-mesos,代碼行數:23,代碼來源:HttpServer.java

示例10: getDashboardJettyServer

import org.eclipse.jetty.util.thread.QueuedThreadPool; //導入依賴的package包/類
/**
 * Creates the Jetty server instance for the admin Dashboard and configures it with the @Named("DashboardContext").
 * @param port where the service is available
 * @param acceptorThreads no. of acceptors
 * @param maxWorkerThreads max no. of worker threads
 * @return Jetty Server instance
 */
@Named("DashboardJettyServer")
@Provides
@Singleton
Server getDashboardJettyServer(@Named("Dashboard.service.port") int port,
		@Named("Dashboard.service.acceptors") int acceptorThreads,
		@Named("Dashboard.service.selectors") int selectorThreads,
		@Named("Dashboard.service.workers") int maxWorkerThreads,
		@Named("DashboardContext") WebAppContext webappContext) {
	QueuedThreadPool threadPool = new QueuedThreadPool();
       threadPool.setMaxThreads(maxWorkerThreads);
	Server server = new Server(threadPool);
	ServerConnector http = new ServerConnector(server, acceptorThreads, selectorThreads);
	http.setPort(port);
	server.addConnector(http);
	server.setHandler(webappContext);
	server.setStopAtShutdown(true);
	return server;
}
 
開發者ID:flipkart-incubator,項目名稱:flux,代碼行數:26,代碼來源:ContainerModule.java

示例11: init

import org.eclipse.jetty.util.thread.QueuedThreadPool; //導入依賴的package包/類
@Override
public void init() throws ServletException {
    try {
        sslContextFactory.start();

        QueuedThreadPool threads = new QueuedThreadPool();
        threads.setName("client");
        client.setExecutor(threads);
        client.setSelectors(1);
        client.start();

        logger.info(String.format("Created %s", client));
    } catch (Exception x) {
        throw new ServletException(x);
    }
}
 
開發者ID:jetty-project,項目名稱:jetty-http2-from-webapp,代碼行數:17,代碼來源:HTTP2Servlet.java

示例12: doStart

import org.eclipse.jetty.util.thread.QueuedThreadPool; //導入依賴的package包/類
@Override
protected void doStart() throws Exception {

    super.doStart();

    metricRegistry.register(MetricRegistry.name(QueuedThreadPool.class, getName(), "size"),
            (Gauge<Integer>) this::getThreads);

    metricRegistry.register(MetricRegistry.name(QueuedThreadPool.class, getName(), "queued-requests"),
            (Gauge<Integer>) this::getQueuedRequests);

    metricRegistry.register(MetricRegistry.name(QueuedThreadPool.class, getName(), "utilization"),
            (Gauge<Double>) this::getUtilization);

    // deprecated metrics
    metricRegistry.register(MetricRegistry.name(QueuedThreadPool.class, getName(), "utilization-max"),
            createUtilizationMaxGauge());
}
 
開發者ID:bootique,項目名稱:bootique-jetty,代碼行數:19,代碼來源:InstrumentedQueuedThreadPool.java

示例13: newInstance

import org.eclipse.jetty.util.thread.QueuedThreadPool; //導入依賴的package包/類
public static void newInstance(String host, int port, int maxThreads, int minThreads, int threadTimeoutMillis) {
    TinyHandler tinyHandler = TinyHandler.get();
    JettyHandler jettyHandler = new JettyHandler(tinyHandler);
    QueuedThreadPool queuedThreadPool = new QueuedThreadPool(minThreads, maxThreads, threadTimeoutMillis);
    queuedThreadPool.setDetailedDump(false);
    Server server = new Server(queuedThreadPool);
    ServerConnector connector = getConnector(server, host, port);
    connector.setAcceptQueueSize(1000);
    server = connector.getServer();
    server.setConnectors(new Connector[]{connector});
    server.setHandler(jettyHandler);
    try {
        server.start();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(100);
    }
}
 
開發者ID:WhiteBlue,項目名稱:eleme-hackathon,代碼行數:20,代碼來源:JettyServerFactory.java

示例14: RestfulServer

import org.eclipse.jetty.util.thread.QueuedThreadPool; //導入依賴的package包/類
public RestfulServer(boolean loopback,
    int port,
    String applicationName,
    boolean sslEnabled,
    String keyStoreAlias,
    String keyStorePassword,
    String keyStorePath,
    int maxNumberOfThreads,
    int maxQueuedRequests) {

    this.applicationName = applicationName;
    int maxThreads = maxNumberOfThreads + ACCEPTORS + SELECTORS;
    BlockingArrayQueue<Runnable> queue = new BlockingArrayQueue<>(MIN_THREADS, MIN_THREADS, maxQueuedRequests);
    this.queuedThreadPool = new QueuedThreadPool(maxThreads, MIN_THREADS, IDLE_TIMEOUT, queue);
    this.server = new Server(queuedThreadPool);
    this.handlers = new ContextHandlerCollection();

    server.addEventListener(new MBeanContainer(ManagementFactory.getPlatformMBeanServer()));
    server.setHandler(handlers);

    if (sslEnabled) {
        server.addConnector(makeSslConnector(keyStoreAlias, keyStorePassword, keyStorePath, port));
    } else {
        server.addConnector(makeConnector(loopback, port));
    }
}
 
開發者ID:jivesoftware,項目名稱:routing-bird,代碼行數:27,代碼來源:RestfulServer.java

示例15: jettyEmbeddedServletContainerFactory

import org.eclipse.jetty.util.thread.QueuedThreadPool; //導入依賴的package包/類
@Bean
public JettyEmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory(
        @Value("${server.port:8080}") final String port,
        @Value("${jetty.threadPool.maxThreads:200}") final String maxThreads,
        @Value("${jetty.threadPool.minThreads:8}") final String minThreads,
        @Value("${jetty.threadPool.idleTimeout:60000}") final String idleTimeout) {
    final JettyEmbeddedServletContainerFactory factory =
            new JettyEmbeddedServletContainerFactory(Integer.valueOf(port));
    factory.addServerCustomizers((JettyServerCustomizer) server -> {
        final QueuedThreadPool threadPool = server.getBean(QueuedThreadPool.class);
        threadPool.setMaxThreads(Integer.valueOf(maxThreads));
        threadPool.setMinThreads(Integer.valueOf(minThreads));
        threadPool.setIdleTimeout(Integer.valueOf(idleTimeout));

        final GzipHandler gzipHandler = new GzipHandler();
        gzipHandler.setHandler(server.getHandler());
        gzipHandler.setSyncFlush(true);
        server.setHandler(gzipHandler);
    });
    return factory;
}
 
開發者ID:zalando,項目名稱:nakadi,代碼行數:22,代碼來源:JettyConfig.java


注:本文中的org.eclipse.jetty.util.thread.QueuedThreadPool類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。