示例#1
0
  /* ------------------------------------------------------------ */
  protected void doStart() throws Exception {
    if (_server == null) throw new IllegalStateException("No server");

    // open listener port
    open();

    super.doStart();

    if (_threadPool == null) _threadPool = _server.getThreadPool();
    if (_threadPool != _server.getThreadPool() && (_threadPool instanceof LifeCycle))
      ((LifeCycle) _threadPool).start();

    // Start selector thread
    synchronized (this) {
      _acceptorThread = new Thread[getAcceptors()];

      for (int i = 0; i < _acceptorThread.length; i++) {
        if (!_threadPool.dispatch(new Acceptor(i))) {
          Log.warn("insufficient maxThreads configured for {}", this);
          break;
        }
      }
    }

    Log.info("Started {}", this);
  }
示例#2
0
  /* ------------------------------------------------------------ */
  protected void doStop() throws Exception {
    try {
      close();
    } catch (IOException e) {
      Log.warn(e);
    }

    if (_threadPool == _server.getThreadPool()) _threadPool = null;
    else if (_threadPool instanceof LifeCycle) ((LifeCycle) _threadPool).stop();

    super.doStop();

    Thread[] acceptors = null;
    synchronized (this) {
      acceptors = _acceptorThread;
      _acceptorThread = null;
    }
    if (acceptors != null) {
      for (int i = 0; i < acceptors.length; i++) {
        Thread thread = acceptors[i];
        if (thread != null) thread.interrupt();
      }
    }
  }