예제 #1
0
  /**
   * Stops the timer, cancelling all tasks
   *
   * @throws InterruptedException if interrupted while waiting for thread to return
   */
  public void stop() {
    stopRunner();

    List<Runnable> remaining_tasks = pool.shutdownNow();
    for (Runnable task : remaining_tasks) {
      if (task instanceof Future) {
        Future future = (Future) task;
        future.cancel(true);
      }
    }
    pool.getQueue().clear();
    try {
      pool.awaitTermination(Global.THREADPOOL_SHUTDOWN_WAIT_TIME, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
    }
  }
예제 #2
0
  @Override
  public synchronized void close() throws SecurityException {
    if (pool.isShutdown()) {
      return;
    }

    try {
      // first, anything in the retry queue should be tried one last time and then we give up on it
      allowRetry = false;
      for (LogglySample sample : retryQueue) {
        pool.submit(sample);
      }
      retryQueue.clear();

      System.out.println(
          "Shutting down Loggly handler - waiting 90 seconds for "
              + pool.getQueue().size()
              + " logs to finish");
      pool.shutdown();
      try {
        boolean result = pool.awaitTermination(90, TimeUnit.SECONDS);
        if (!result) {
          System.out.println(
              "Not all Loggly messages sent out - still had "
                  + pool.getQueue().size()
                  + " left :(");
          pool.shutdownNow();
        }
      } catch (InterruptedException e) {
        // ignore
      }
    } finally {
      httpClient.getConnectionManager().shutdown();
      System.out.println("Loggly handler shut down");
    }
  }
예제 #3
0
  @Override
  public void stop() {

    if (sharedHttpServers != null) {
      for (HttpServer server : sharedHttpServers.values()) {
        server.close();
      }
      sharedHttpServers = null;
    }

    if (sharedNetServers != null) {
      for (NetServer server : sharedNetServers.values()) {
        server.close();
      }
      sharedNetServers = null;
    }

    if (timer != null) {
      timer.stop();
      timer = null;
    }

    if (eventBus != null) {
      eventBus.close(null);
    }

    if (backgroundPool != null) {
      backgroundPool.shutdown();
    }

    if (acceptorPool != null) {
      acceptorPool.shutdown();
    }

    try {
      if (backgroundPool != null) {
        backgroundPool.awaitTermination(20, TimeUnit.SECONDS);
        backgroundPool = null;
      }
    } catch (InterruptedException ex) {
      // ignore
    }

    try {
      if (acceptorPool != null) {
        acceptorPool.awaitTermination(20, TimeUnit.SECONDS);
        acceptorPool = null;
      }
    } catch (InterruptedException ex) {
      // ignore
    }

    // log.info("Release external resources from worker pool");
    if (corePool != null) {
      corePool.releaseExternalResources();
      corePool = null;
    }
    // log.info("Release external resources: done");

    setContext(null);
  }