Refine search
public static void join() { try { server.getThreadPool().join(); } catch (Exception e) { Data.logger.warn("", e); } }
@Override public int activeThreadCount() { if (server == null) { return 0; } return server.getThreadPool().getThreads() - server.getThreadPool().getIdleThreads(); }
protected void startServer() { try { writePid2File(); super.start(); LOGGER.info("Current thread: {} | Idle thread: {}", super.getThreadPool().getThreads(), super.getThreadPool().getIdleThreads()); super.join(); } catch (final Throwable e) { // NANO-386: fixed Address already in use bug LOGGER.error("Bootstrap server error: {}", e.getMessage()); System.exit(1); } }
@PostConstruct public void start() throws Exception { server.start(); checkState(server.isStarted(), "server is not started"); // The combination of an NIO connector and an insufficient number of threads results // in a server that hangs after accepting connections. Jetty scales the number of // required threads based on the number of available processors in a non-trivial way, // so a config that works on one machine might fail on a larger machine without an // obvious reason why. Thus, we need this runtime check after startup as a safeguard. checkSufficientThreads(httpConnector, "HTTP"); checkSufficientThreads(httpsConnector, "HTTPS"); checkSufficientThreads(adminConnector, "admin"); checkState(!server.getThreadPool().isLowOnThreads(), "insufficient threads configured for server connector"); }
public boolean isLowResources() { if (_threadPool != null) return _threadPool.isLowOnThreads(); return _server.getThreadPool().isLowOnThreads(); }
protected void execute(Runnable task) { getServer().getThreadPool().dispatch(task); }
@Override protected void doStart() throws Exception { if (_server == null) throw new IllegalStateException("No server"); // open listener port open(); if (_threadPool == null) { _threadPool = _server.getThreadPool(); addBean(_threadPool,false); } super.doStart(); // Start selector thread synchronized (this) { _acceptorThreads = new Thread[getAcceptors()]; for (int i = 0; i < _acceptorThreads.length; i++) if (!_threadPool.dispatch(new Acceptor(i))) throw new IllegalStateException("!accepting"); if (_threadPool.isLowOnThreads()) LOG.warn("insufficient threads configured for {}",this); } LOG.info("Started {}",this); }
@Override public void run() { ready.countDown(); try { start.await(); assertEquals("a:b\nc:d\n", readOutput(new URL(baseUrl, "/echo?a=b&c=d"))); int serverThreads = server.webServer.getThreadPool().getThreads(); assertTrue("More threads are started than expected, Server Threads count: " + serverThreads, serverThreads <= MAX_THREADS); System.out.println("Number of threads = " + serverThreads + " which is less or equal than the max = " + MAX_THREADS); } catch (Exception e) { // do nothing } } });
@Override public boolean isLowOnResources() { ThreadPool serverThreads = _server.getThreadPool(); if(serverThreads.isLowOnThreads()) { reason ="Server low on threads: "+serverThreads.getThreads()+", idleThreads:"+serverThreads.getIdleThreads(); return true; } for(Connector connector : getMonitoredConnectors()) { Executor executor = connector.getExecutor(); if (executor instanceof ThreadPool && executor!=serverThreads) { ThreadPool connectorThreads=(ThreadPool)executor; if (connectorThreads.isLowOnThreads()) { reason ="Connector low on threads: "+connectorThreads; return true; } } } return false; }
@OnWebSocketConnect @SuppressWarnings("unused") public void onWebSocketConnect(final Session session) { SocketAddress localAddress = session.getLocalAddress(); SocketAddress remoteAddress = session.getRemoteAddress(); _protocolEngine = _factory.newProtocolEngine(remoteAddress); // Let AMQP do timeout handling session.setIdleTimeout(0); _connectionWrapper = new ConnectionWrapper(session, localAddress, remoteAddress, _protocolEngine, _server.getThreadPool()); if (session.getUpgradeRequest() instanceof ServletUpgradeRequest) { ServletUpgradeRequest upgradeRequest = (ServletUpgradeRequest) session.getUpgradeRequest(); if (upgradeRequest.getCertificates() != null && upgradeRequest.getCertificates().length > 0) { _connectionWrapper.setPeerCertificate(upgradeRequest.getCertificates()[0]); } } _protocolEngine.setNetworkConnection(_connectionWrapper); _protocolEngine.setWorkListener(object -> _server.getThreadPool().execute(() -> _connectionWrapper.doWork())); _activeConnections.add(_connectionWrapper); _idleTimeoutChecker.wakeup(); }
@Override public boolean dispatch(Runnable task) { return _threadPool.dispatch(task); }
private static void checkSufficientThreads(Connector connector, String name) { if (connector == null) { return; } Executor executor = connector.getExecutor(); if (executor instanceof ThreadPool) { ThreadPool queuedThreadPool = (ThreadPool) executor; checkState(!queuedThreadPool.isLowOnThreads(), "insufficient threads configured for %s connector", name); } }
ThreadPool threadPool = new ThreadPool(2); threadPool.runTask(startServer(serverSocket)); threadPool.join(); threadPool.destroy();
ThreadPool pool=new ThreadPool(this); pool.start(); .. some code pool.execute(new task()); .. other code pool.execute(new task()); .. other code pool.execute(new task());
public class Test { public void startExecution() { Queue<String> runQ = new LinkedList<>(); ThreadPool threadPool = new ThreadPool(threadCount,timeOut); while (!runQ.isEmpty()) { String TaskName = runQ.remove(); Task t = new Task(TaskName); threadPool.execute(t, TaskName); } if (threadPool.awaitTermination(timeOut, TimeUnit.MINUTES)) { System.out.println("[CONTROL: ALL TEST TASKS COMPLETED SUCCESSFULLY.]"); } else { System.out.println("[CONTROL: ALL THE TEST TASKS DID NOT COMPLETE SUCCESSFULLY IN STIPULATED TIME. FORCEFULLY FINALIZING.]"); threadPool.shutdownNow(); } } }
public void tick() { _threadPool.execute(_tickJob); } }
public boolean isLowResources() { if (_threadPool != null) return _threadPool.isLowOnThreads(); return _server.getThreadPool().isLowOnThreads(); }
public void start(final Runnable run) { final AsyncEventState event=_event; if (event!=null) { _connection.getServer().getThreadPool().dispatch(new Runnable() { public void run() { ((Context)event.getServletContext()).getContextHandler().handle(run); } }); } }
@Override protected void doStart() throws Exception { if (_server == null) throw new IllegalStateException("No server"); // open listener port open(); if (_threadPool == null) { _threadPool = _server.getThreadPool(); addBean(_threadPool,false); } super.doStart(); // Start selector thread synchronized (this) { _acceptorThreads = new Thread[getAcceptors()]; for (int i = 0; i < _acceptorThreads.length; i++) if (!_threadPool.dispatch(new Acceptor(i))) throw new IllegalStateException("!accepting"); if (_threadPool.isLowOnThreads()) LOG.warn("insufficient threads configured for {}",this); } LOG.info("Started {}",this); }
@Override public int getJettyCQSRequestHandlerPoolSize() { return CMB.cqsServer.getThreadPool().getThreads(); }