Java Code Examples for org.eclipse.jetty.util.thread.QueuedThreadPool#setMinThreads()
The following examples show how to use
org.eclipse.jetty.util.thread.QueuedThreadPool#setMinThreads() .
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: AmforeasJetty.java From amforeas with GNU General Public License v3.0 | 6 votes |
protected void startServer (final AmforeasConfiguration conf) throws Exception { final QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setMinThreads(conf.getServerThreadsMin()); threadPool.setMaxThreads(conf.getServerThreadsMax()); final Server server = new Server(threadPool); setupJerseyServlet(conf, server); setupHTTPConnection(conf, server); setupHTTPSConnection(conf, server); server.start(); server.setStopAtShutdown(true); server.join(); }
Example 2
Source File: BeanConfiguration.java From sagemaker-sparkml-serving-container with Apache License 2.0 | 5 votes |
@Bean public JettyServletWebServerFactory provideJettyServletWebServerFactory() { final JettyServletWebServerFactory jettyServlet = new JettyServletWebServerFactory( new Integer(this.getHttpListenerPort())); final List<JettyServerCustomizer> serverCustomizerList = Lists.newArrayList(); final JettyServerCustomizer serverCustomizer = server -> { final QueuedThreadPool threadPool = server.getBean(QueuedThreadPool.class); threadPool.setMinThreads(SystemUtils.getNumberOfThreads(MIN_CORE_TO_THREAD_RATIO)); threadPool.setMaxThreads(SystemUtils.getNumberOfThreads(MAX_CORE_TO_THREAD_RATIO)); }; serverCustomizerList.add(serverCustomizer); jettyServlet.setServerCustomizers(serverCustomizerList); return jettyServlet; }
Example 3
Source File: JettyManager.java From n4js with Eclipse Public License 1.0 | 5 votes |
private ThreadPool configureThreadPool(final int port) { final QueuedThreadPool threadPool = new QueuedThreadPool(threadPoolCapacity); threadPool.setMinThreads(minThreadCount); threadPool.setMaxThreads(maxThreadCount); threadPool.setName("Jetty thread pool [" + port + "]"); threadPool.setDetailedDump(true); return threadPool; }
Example 4
Source File: JettyServerThreadPoolMetricsTest.java From micrometer with Apache License 2.0 | 5 votes |
@BeforeEach void setup() throws Exception { registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock()); Iterable<Tag> tags = Collections.singletonList(Tag.of("id", "0")); QueuedThreadPool threadPool = new InstrumentedQueuedThreadPool(registry, tags); threadPool.setMinThreads(32); threadPool.setMaxThreads(100); server = new Server(threadPool); ServerConnector connector = new ServerConnector(server); server.setConnectors(new Connector[] { connector }); server.start(); }
Example 5
Source File: JettyHttpServer.java From dubbox with Apache License 2.0 | 5 votes |
public JettyHttpServer(URL url, final HttpHandler handler) { super(url, handler); DispatcherServlet.addHttpHandler(url.getPort(), handler); int threads = url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS); QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setDaemon(true); threadPool.setMaxThreads(threads); threadPool.setMinThreads(threads); server = new Server(threadPool); // HTTP connector ServerConnector connector = new ServerConnector(server); if (!url.isAnyHost() && NetUtils.isValidLocalHost(url.getHost())) { connector.setHost(url.getHost()); } connector.setPort(url.getPort()); // connector.setIdleTimeout(30000); server.addConnector(connector); ServletHandler servletHandler = new ServletHandler(); ServletHolder servletHolder = servletHandler.addServletWithMapping(DispatcherServlet.class, "/*"); servletHolder.setInitOrder(2); server.insertHandler(servletHandler); try { server.start(); } catch (Exception e) { throw new IllegalStateException("Failed to start jetty server on " + url.getAddress() + ", cause: " + e.getMessage(), e); } }
Example 6
Source File: JettyHttpServer.java From dubbo-rpc-jsonrpc with Apache License 2.0 | 5 votes |
public JettyHttpServer(URL url, final HttpHandler handler) { super(url, handler); DispatcherServlet.addHttpHandler(url.getPort(), handler); int threads = url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS); QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setDaemon(true); threadPool.setMaxThreads(threads); threadPool.setMinThreads(threads); server = new Server(threadPool); // HTTP connector ServerConnector connector = new ServerConnector(server); if (!url.isAnyHost() && NetUtils.isValidLocalHost(url.getHost())) { connector.setHost(url.getHost()); } connector.setPort(url.getPort()); // connector.setIdleTimeout(30000); server.addConnector(connector); ServletHandler servletHandler = new ServletHandler(); ServletHolder servletHolder = servletHandler.addServletWithMapping(DispatcherServlet.class, "/*"); servletHolder.setInitOrder(2); server.insertHandler(servletHandler); try { server.start(); } catch (Exception e) { throw new IllegalStateException("Failed to start jetty server on " + url.getAddress() + ", cause: " + e.getMessage(), e); } }
Example 7
Source File: JettyServerWrapper.java From cougar with Apache License 2.0 | 4 votes |
public void initialiseConnectors() throws Exception { threadPool = new QueuedThreadPool(); threadPool.setMaxThreads(maxThreads); threadPool.setMinThreads(minThreads); threadPool.setName("JettyThread"); jettyServer = new Server(threadPool); jettyServer.setStopAtShutdown(true); MBeanContainer container = new MBeanContainer(mbeanServer); jettyServer.addBean(container); LowResourceMonitor lowResourcesMonitor = new LowResourceMonitor(jettyServer); lowResourcesMonitor.setPeriod(lowResourcesPeriod); lowResourcesMonitor.setLowResourcesIdleTimeout(lowResourcesIdleTime); lowResourcesMonitor.setMonitorThreads(lowResourcesMonitorThreads); lowResourcesMonitor.setMaxConnections(lowResourcesMaxConnections); lowResourcesMonitor.setMaxMemory(lowResourcesMaxMemory); lowResourcesMonitor.setMaxLowResourcesTime(lowResourcesMaxTime); jettyServer.addBean(lowResourcesMonitor); // US24803 - Needed for preventing Hashtable key collision DoS CVE-2012-2739 jettyServer.setAttribute("org.eclipse.jetty.server.Request.maxFormContentSize", maxFormContentSize); List<Connector> connectors = new ArrayList<Connector>(); if (httpPort != -1) { httpConfiguration = createHttpConfiguration(); setBufferSizes(httpConfiguration); if (httpForwarded) { httpConfiguration.addCustomizer(new ForwardedRequestCustomizer()); } httpConnector = createHttpConnector(jettyServer, httpConfiguration, httpAcceptors, httpSelectors); httpConnector.setPort(httpPort); httpConnector.setReuseAddress(httpReuseAddress); httpConnector.setIdleTimeout(httpMaxIdle); httpConnector.setAcceptQueueSize(httpAcceptQueueSize); httpConnector.addBean(new ConnectorStatistics()); connectors.add(httpConnector); } if (httpsPort != -1) { SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setKeyStorePath(httpsKeystore.getFile().getCanonicalPath()); sslContextFactory.setKeyStoreType(httpsKeystoreType); sslContextFactory.setKeyStorePassword(httpsKeyPassword); if (StringUtils.isNotBlank(httpsCertAlias)) { sslContextFactory.setCertAlias(httpsCertAlias); } sslContextFactory.setKeyManagerPassword(httpsKeyPassword); // if you need it then you defo want it sslContextFactory.setWantClientAuth(httpsNeedClientAuth || httpsWantClientAuth); sslContextFactory.setNeedClientAuth(httpsNeedClientAuth); sslContextFactory.setRenegotiationAllowed(httpsAllowRenegotiate); httpsConfiguration = createHttpConfiguration(); setBufferSizes(httpsConfiguration); if (httpsForwarded) { httpsConfiguration.addCustomizer(new ForwardedRequestCustomizer()); } httpsConnector = createHttpsConnector(jettyServer, httpsConfiguration, httpsAcceptors, httpsSelectors, sslContextFactory); httpsConnector.setPort(httpsPort); httpsConnector.setReuseAddress(httpsReuseAddress); httpsConnector.setIdleTimeout(httpsMaxIdle); httpsConnector.setAcceptQueueSize(httpsAcceptQueueSize); httpsConnector.addBean(new ConnectorStatistics()); mbeanServer.registerMBean(getKeystoreCertificateChains(), new ObjectName("CoUGAR.https:name=keyStore")); // truststore is not required if we don't want client auth if (httpsWantClientAuth) { sslContextFactory.setTrustStorePath(httpsTruststore.getFile().getCanonicalPath()); sslContextFactory.setTrustStoreType(httpsTruststoreType); sslContextFactory.setTrustStorePassword(httpsTrustPassword); mbeanServer.registerMBean(getTruststoreCertificateChains(), new ObjectName("CoUGAR.https:name=trustStore")); } connectors.add(httpsConnector); } if (connectors.size() == 0) { throw new IllegalStateException("HTTP transport requires at least one port enabled to function correctly."); } jettyServer.setConnectors(connectors.toArray(new Connector[connectors.size()])); }
Example 8
Source File: HttpServer2.java From hadoop-ozone with Apache License 2.0 | 4 votes |
/** * Set the min, max number of worker threads (simultaneous connections). */ public void setThreads(int min, int max) { QueuedThreadPool pool = (QueuedThreadPool) webServer.getThreadPool(); pool.setMinThreads(min); pool.setMaxThreads(max); }
Example 9
Source File: ServerDaemon.java From cloudstack with Apache License 2.0 | 4 votes |
@Override public void start() throws Exception { // Thread pool final QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setMinThreads(10); threadPool.setMaxThreads(500); // Jetty Server server = new Server(threadPool); // Setup Scheduler server.addBean(new ScheduledExecutorScheduler()); // Setup JMX final MBeanContainer mbeanContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer()); server.addBean(mbeanContainer); // HTTP config final HttpConfiguration httpConfig = new HttpConfiguration(); httpConfig.addCustomizer( new ForwardedRequestCustomizer() ); httpConfig.setSecureScheme("https"); httpConfig.setSecurePort(httpsPort); httpConfig.setOutputBufferSize(32768); httpConfig.setRequestHeaderSize(8192); httpConfig.setResponseHeaderSize(8192); httpConfig.setSendServerVersion(false); httpConfig.setSendDateHeader(false); // HTTP Connector createHttpConnector(httpConfig); // Setup handlers Pair<SessionHandler,HandlerCollection> pair = createHandlers(); server.setHandler(pair.second()); // Extra config options server.setStopAtShutdown(true); // HTTPS Connector createHttpsConnector(httpConfig); server.start(); // Must set the session timeout after the server has started pair.first().setMaxInactiveInterval(sessionTimeout * 60); server.join(); }
Example 10
Source File: EsigateServer.java From esigate with Apache License 2.0 | 4 votes |
/** * Create and start server. * * @throws Exception * when server cannot be started. */ public static void start() throws Exception { MetricRegistry registry = new MetricRegistry(); QueuedThreadPool threadPool = new InstrumentedQueuedThreadPool(registry); threadPool.setName("esigate"); threadPool.setMaxThreads(maxThreads); threadPool.setMinThreads(minThreads); srv = new Server(threadPool); srv.setStopAtShutdown(true); srv.setStopTimeout(5000); // HTTP Configuration HttpConfiguration httpConfig = new HttpConfiguration(); httpConfig.setOutputBufferSize(outputBufferSize); httpConfig.setSendServerVersion(false); Timer processTime = registry.timer("processTime"); try (ServerConnector connector = new InstrumentedServerConnector("main", EsigateServer.port, srv, registry, new InstrumentedConnectionFactory(new HttpConnectionFactory(httpConfig), processTime)); ServerConnector controlConnector = new ServerConnector(srv)) { // Main connector connector.setIdleTimeout(EsigateServer.idleTimeout); connector.setSoLingerTime(-1); connector.setName("main"); connector.setAcceptQueueSize(200); // Control connector controlConnector.setHost("127.0.0.1"); controlConnector.setPort(EsigateServer.controlPort); controlConnector.setName("control"); srv.setConnectors(new Connector[] {connector, controlConnector}); // War ProtectionDomain protectionDomain = EsigateServer.class.getProtectionDomain(); String warFile = protectionDomain.getCodeSource().getLocation().toExternalForm(); String currentDir = new File(protectionDomain.getCodeSource().getLocation().getPath()).getParent(); File workDir = resetTempDirectory(currentDir); WebAppContext context = new WebAppContext(warFile, EsigateServer.contextPath); context.setServer(srv); context.setTempDirectory(workDir); if (StringUtils.isNoneEmpty(sessionCookieName)) { context.getSessionHandler().getSessionCookieConfig().setName(sessionCookieName); } // Add extra classpath (allows to add extensions). if (EsigateServer.extraClasspath != null) { context.setExtraClasspath(EsigateServer.extraClasspath); } // Add the handlers HandlerCollection handlers = new HandlerList(); // control handler must be the first one. // Work in progress, currently disabled. handlers.addHandler(new ControlHandler(registry)); InstrumentedHandler ih = new InstrumentedHandler(registry); ih.setName("main"); ih.setHandler(context); handlers.addHandler(ih); srv.setHandler(handlers); srv.start(); srv.join(); } }
Example 11
Source File: CardFantasyJettyServer.java From CardFantasy with BSD 2-Clause "Simplified" License | 4 votes |
public static void main(String[] args) throws Exception { int port = 7878; if (args.length > 1) { if ("-port".equalsIgnoreCase(args[0])) { try { port = Integer.parseInt(args[1]); } catch (Exception e) { throw new IllegalArgumentException("Invalid port number " + args[1]); } } } QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setMaxThreads(128); threadPool.setMinThreads(32); Server server = new Server(threadPool); ServerConnector connector = new ServerConnector(server); connector.setPort(port); server.addConnector(connector); HandlerList handlers = new HandlerList(); handlers.addHandler(new AbstractHandler() { @Override public void handle(String s, Request jettyRequest, HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws IOException, ServletException { servletResponse.setCharacterEncoding("UTF-8"); jettyRequest.setHandled(false); } }); ServletHandler servletHandler = new ServletHandler(); servletHandler.addServletWithMapping(BossGameJettyServlet.class, "/PlayBossMassiveGame"); servletHandler.addServletWithMapping(ArenaGameJettyServlet.class, "/PlayAutoMassiveGame"); servletHandler.addServletWithMapping(MapGameJettyServlet.class, "/PlayMapMassiveGame"); servletHandler.addServletWithMapping(LilithGameJettyServlet.class, "/PlayLilithMassiveGame"); servletHandler.addServletWithMapping(PingJettyServlet.class, "/Ping"); handlers.addHandler(servletHandler); server.setHandler(handlers); server.start(); server.join(); }
Example 12
Source File: HttpServer2.java From knox with Apache License 2.0 | 4 votes |
public void setThreads(int min, int max) { QueuedThreadPool pool = (QueuedThreadPool) webServer.getThreadPool(); pool.setMinThreads(min); pool.setMaxThreads(max); }
Example 13
Source File: HttpServer2.java From knox with Apache License 2.0 | 4 votes |
public void setThreads(int min, int max) { QueuedThreadPool pool = (QueuedThreadPool) webServer.getThreadPool(); pool.setMinThreads(min); pool.setMaxThreads(max); }
Example 14
Source File: HttpServer.java From hbase with Apache License 2.0 | 4 votes |
/** * Set the min, max number of worker threads (simultaneous connections). */ public void setThreads(int min, int max) { QueuedThreadPool pool = (QueuedThreadPool) webServer.getThreadPool(); pool.setMinThreads(min); pool.setMaxThreads(max); }
Example 15
Source File: StreamingReceiver.java From kylin with Apache License 2.0 | 4 votes |
private ThreadPool createThreadPool(KylinConfig kylinConfig) { QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setMinThreads(kylinConfig.getStreamingReceiverHttpMinThreads()); threadPool.setMaxThreads(kylinConfig.getStreamingReceiverHttpMaxThreads()); return threadPool; }
Example 16
Source File: HttpServer2.java From lucene-solr with Apache License 2.0 | 4 votes |
/** * Set the min, max number of worker threads (simultaneous connections). */ public void setThreads(int min, int max) { QueuedThreadPool pool = (QueuedThreadPool) webServer.getThreadPool(); pool.setMinThreads(min); pool.setMaxThreads(max); }
Example 17
Source File: JettyAdapter.java From enkan with Eclipse Public License 1.0 | 4 votes |
private ThreadPool createThreadPool() { QueuedThreadPool pool = new QueuedThreadPool(50); pool.setMinThreads(8); return pool; }
Example 18
Source File: WebServerTools.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
public static Server start(WebServer webServer) throws Exception { /** * 更新x_desktop的center指向 */ updateCenterConfigJson(); /** * 更新 favicon.ico */ updateFavicon(); /** * 创建index.html */ createIndexPage(); QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setMinThreads(WEBSERVER_THREAD_POOL_SIZE_MIN); threadPool.setMaxThreads(WEBSERVER_THREAD_POOL_SIZE_MAX); Server server = new Server(threadPool); if (webServer.getSslEnable()) { addHttpsConnector(server, webServer.getPort()); } else { addHttpConnector(server, webServer.getPort()); } WebAppContext context = new WebAppContext(); context.setContextPath("/"); context.setBaseResource(Resource.newResource(new File(Config.base(), "servers/webServer"))); // context.setResourceBase("."); context.setParentLoaderPriority(true); context.setExtractWAR(false); // context.setDefaultsDescriptor(new File(Config.base(), // "commons/webdefault_w.xml").getAbsolutePath()); context.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "" + webServer.getDirAllowed()); context.setInitParameter("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false"); if (webServer.getCacheControlMaxAge() > 0) { context.setInitParameter("org.eclipse.jetty.servlet.Default.cacheControl", "max-age=" + webServer.getCacheControlMaxAge()); } context.setInitParameter("org.eclipse.jetty.servlet.Default.maxCacheSize", "256000000"); context.setInitParameter("org.eclipse.jetty.servlet.Default.maxCachedFileSize", "200000000"); context.setWelcomeFiles(new String[] { "default.html", "index.html" }); context.setGzipHandler(new GzipHandler()); context.setParentLoaderPriority(true); context.getMimeTypes().addMimeMapping("wcss", "application/json"); /* stat */ if (webServer.getStatEnable()) { FilterHolder statFilterHolder = new FilterHolder(new WebStatFilter()); statFilterHolder.setInitParameter("exclusions", webServer.getStatExclusions()); context.addFilter(statFilterHolder, "/*", EnumSet.of(DispatcherType.REQUEST)); ServletHolder statServletHolder = new ServletHolder(StatViewServlet.class); statServletHolder.setInitParameter("sessionStatEnable", "false"); context.addServlet(statServletHolder, "/druid/*"); } /* stat end */ server.setHandler(context); server.setDumpAfterStart(false); server.setDumpBeforeStop(false); server.setStopAtShutdown(true); server.start(); context.setMimeTypes(Config.mimeTypes()); System.out.println("****************************************"); System.out.println("* web server start completed."); System.out.println("* port: " + webServer.getPort() + "."); System.out.println("****************************************"); return server; }
Example 19
Source File: StreamingReceiver.java From kylin-on-parquet-v2 with Apache License 2.0 | 4 votes |
private ThreadPool createThreadPool(KylinConfig kylinConfig) { QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setMinThreads(kylinConfig.getStreamingReceiverHttpMinThreads()); threadPool.setMaxThreads(kylinConfig.getStreamingReceiverHttpMaxThreads()); return threadPool; }
Example 20
Source File: JettyFactory.java From kumuluzee with MIT License | 3 votes |
private ThreadPool createThreadPool() { QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setMinThreads(serverConfig.getMinThreads()); threadPool.setMaxThreads(serverConfig.getMaxThreads()); log.info("Starting KumuluzEE on Jetty with " + serverConfig.getMinThreads() + " minimum " + "and " + serverConfig.getMaxThreads() + " maximum threads"); return threadPool; }