/** {@inheritDoc} */
    @Override
    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
      try {
        if (executor.isShutdown()) throw new RejectedExecutionException();
        else executor.getQueue().put(r);
      } catch (InterruptedException ignored) {
        U.warn(log, "Working thread was interrupted while loading data.");

        Thread.currentThread().interrupt();
      }
    }
 public void rejectedExecution(Runnable task, ThreadPoolExecutor executor) {
   ((DebuggableThreadPoolExecutor) executor).onInitialRejection(task);
   BlockingQueue<Runnable> queue = executor.getQueue();
   while (true) {
     if (executor.isShutdown()) {
       ((DebuggableThreadPoolExecutor) executor).onFinalRejection(task);
       throw new RejectedExecutionException("ThreadPoolExecutor has shut down");
     }
     try {
       if (queue.offer(task, 1000, TimeUnit.MILLISECONDS)) {
         ((DebuggableThreadPoolExecutor) executor).onFinalAccept(task);
         break;
       }
     } catch (InterruptedException e) {
       throw new AssertionError(e);
     }
   }
 }
Пример #3
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");
    }
  }
Пример #4
0
 public boolean isShutdown() {
   return pool.isShutdown();
 }
 public boolean isShutdown() {
   return executorService_.isShutdown();
 }