org.eclipse.jetty.util.thread.ThreadPool类的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(258)

本文整理了Java中org.eclipse.jetty.util.thread.ThreadPool类的一些代码示例,展示了ThreadPool类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ThreadPool类的具体详情如下:
包路径:org.eclipse.jetty.util.thread.ThreadPool
类名称:ThreadPool

ThreadPool介绍

[英]ThreadPool. A specialization of Executor interface that provides reporting methods (eg #getThreads()) and the option of configuration methods (e.g. @link SizedThreadPool#setMaxThreads(int)).
[中]线程池。Executor接口的专门化,提供报告方法(例如#getThreads())和配置方法选项(例如@link SizedThreadPool#setMaxThreads(int))。

代码示例

代码示例来源:origin: yacy/yacy_grid_mcp

public static void join() {
  try {
    server.getThreadPool().join();
  } catch (Exception e) {
    Data.logger.warn("", e);
  }
}

代码示例来源:origin: perwendel/spark

@Override
public int activeThreadCount() {
  if (server == null) {
    return 0;
  }
  return server.getThreadPool().getThreads() - server.getThreadPool().getIdleThreads();
}

代码示例来源:origin: org.nanoframework/nano-jetty-server

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);
  }
}

代码示例来源:origin: com.teradata.airlift/http-server

@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");
}

代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-all-server

public boolean isLowResources()
{
  if (_threadPool != null)
    return _threadPool.isLowOnThreads();
  return _server.getThreadPool().isLowOnThreads();
}

代码示例来源:origin: org.eclipse.jetty.spdy/spdy-jetty-http

protected void execute(Runnable task)
{
  getServer().getThreadPool().dispatch(task);
}

代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-all-server

@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);
}

代码示例来源:origin: apache/hbase

@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
  }
 }
});

代码示例来源:origin: jenkinsci/winstone

@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;
}

代码示例来源:origin: org.apache.qpid/qpid-broker-plugins-websocket

@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();
}

代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-all-server

@Override
public boolean dispatch(Runnable task)
{
  return _threadPool.dispatch(task);
}

代码示例来源:origin: com.teradata.airlift/http-server

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);
  }
}

代码示例来源:origin: stackoverflow.com

ThreadPool threadPool = new ThreadPool(2);
threadPool.runTask(startServer(serverSocket));
threadPool.join();
threadPool.destroy();

代码示例来源:origin: stackoverflow.com

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());

代码示例来源:origin: stackoverflow.com

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();

}
}
}

代码示例来源:origin: org.apache.qpid/qpid-broker-plugins-websocket

public void tick()
  {
    _threadPool.execute(_tickJob);
  }
}

代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-webapp

public boolean isLowResources()
{
  if (_threadPool != null)
    return _threadPool.isLowOnThreads();
  return _server.getThreadPool().isLowOnThreads();
}

代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-all-server

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);
      }
    });
  }
}

代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-server

@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);
}

代码示例来源:origin: Comcast/cmb

@Override
public int getJettyCQSRequestHandlerPoolSize() {
  return CMB.cqsServer.getThreadPool().getThreads();
}

相关文章