Java Code Examples for java.util.concurrent.ThreadPoolExecutor#isShutdown()

The following examples show how to use java.util.concurrent.ThreadPoolExecutor#isShutdown() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DiscardOldPolicyWithReport.java    From sofa-jraft with Apache License 2.0 6 votes vote down vote up
@Override
public void rejectedExecution(final Runnable r, final ThreadPoolExecutor e) {
    LOG.error("Thread pool [{}] is exhausted! {}.", threadPoolName, e.toString());

    dumpJvmInfoIfNeeded();

    if (!e.isShutdown()) {
        final BlockingQueue<Runnable> queue = e.getQueue();
        int discardSize = queue.size() >> 1;
        discardSize = discardSize <= 0 ? 1 : discardSize;
        for (int i = 0; i < discardSize; i++) {
            queue.poll();
        }
        e.execute(r);
    }
}
 
Example 2
Source File: DiscardedPolicyWithReport.java    From Thunder with Apache License 2.0 6 votes vote down vote up
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
    if (threadName != null) {
        LOG.error("Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
    }

    if (!executor.isShutdown()) {
        BlockingQueue<Runnable> queue = executor.getQueue();
        // 舍弃1/2队列元素,例如7个单位的元素,舍弃3个
        int discardSize = queue.size() >> 1;
        for (int i = 0; i < discardSize; i++) {
            // 从头部移除并返问队列头部的元素
            queue.poll();
        }

        // 添加元素,如果队列满,不阻塞,返回false
        queue.offer(runnable);
    }
}
 
Example 3
Source File: RejectedPolicy.java    From Lottor with MIT License 6 votes vote down vote up
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
    if (threadName != null) {
        LOG.error("txTransaction Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
    }

    if (runnable instanceof RejectedRunnable) {
        ((RejectedRunnable) runnable).rejected();
    } else {
        if (!executor.isShutdown()) {
            BlockingQueue<Runnable> queue = executor.getQueue();
            int discardSize = queue.size() >> 1;
            for (int i = 0; i < discardSize; i++) {
                queue.poll();
            }

            try {
                queue.put(runnable);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
 
Example 4
Source File: ScheduledThreadPoolExecutorWithKeepAlive.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
  if (executor.isShutdown()) {
    throw new RejectedExecutionException("executor has been shutdown");
  } else {
    try {
      executor.getQueue().put(r);
    } catch (InterruptedException ie) {
      Thread.currentThread().interrupt();
      RejectedExecutionException e = new RejectedExecutionException("interrupted");
      e.initCause(ie);
      throw e;
    }
  }
}
 
Example 5
Source File: PooledExecutorWithDMStats.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
  if (executor.isShutdown()) {
    throw new RejectedExecutionException(LocalizedStrings.PooledExecutorWithDMStats_EXECUTOR_HAS_BEEN_SHUTDOWN.toLocalizedString());
  } else {
    try {
      PooledExecutorWithDMStats pool = (PooledExecutorWithDMStats)executor;
      pool.bufferQueue.put(r);
    } catch (InterruptedException ie) {
      Thread.currentThread().interrupt();
      RejectedExecutionException e = new RejectedExecutionException(LocalizedStrings.PooledExecutorWithDMStats_INTERRUPTED.toLocalizedString());
      e.initCause(ie);
      throw e;
    }
  }
}
 
Example 6
Source File: BlockingHandler.java    From pdfcompare with Apache License 2.0 5 votes vote down vote up
@Override
public void rejectedExecution(final Runnable r, final ThreadPoolExecutor executor) {
    try {
        if (!executor.isShutdown()) {
            executor.getQueue().put(r);
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
}
 
Example 7
Source File: PooledExecutorWithDMStats.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
  if (executor.isShutdown()) {
    throw new RejectedExecutionException(LocalizedStrings.PooledExecutorWithDMStats_EXECUTOR_HAS_BEEN_SHUTDOWN.toLocalizedString());
  } else {
    try {
      PooledExecutorWithDMStats pool = (PooledExecutorWithDMStats)executor;
      pool.bufferQueue.put(r);
    } catch (InterruptedException ie) {
      Thread.currentThread().interrupt();
      RejectedExecutionException e = new RejectedExecutionException(LocalizedStrings.PooledExecutorWithDMStats_INTERRUPTED.toLocalizedString());
      e.initCause(ie);
      throw e;
    }
  }
}
 
Example 8
Source File: ThreadPoolManager.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
static synchronized ThreadPoolExecutor getExecutor(ThreadPoolBuilder builder,
    Map<String, Object> poolCache) {
  ThreadPoolExecutor pool = (ThreadPoolExecutor) poolCache.get(builder.getName());
  if (pool == null || pool.isTerminating() || pool.isShutdown()) {
    pool = getDefaultExecutor(builder);
    LOG.info("Creating new pool for " + builder.getName());
    poolCache.put(builder.getName(), pool);
  }
  ((ShutdownOnUnusedThreadPoolExecutor) pool).addReference();

  return pool;
}
 
Example 9
Source File: BlockFastProducerPolicy.java    From kinesis-log4j-appender with Apache License 2.0 5 votes vote down vote up
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
  if (executor.isShutdown()) {
    throw new RejectedExecutionException("Threadpoolexecutor already shutdown");
  } else {
    try {
      executor.getQueue().put(r);
    } catch (InterruptedException e) {
      throw new RejectedExecutionException(
          "Thread was interrupted while waiting for space to be available in the threadpool", e);
    }
  }
}
 
Example 10
Source File: DiscardTaskPolicyWithReport.java    From Jupiter with Apache License 2.0 5 votes vote down vote up
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
    logger.error("Thread pool [{}] is exhausted! {}.", threadPoolName, e.toString());

    dumpJvmInfoIfNeeded();

    if (!e.isShutdown()) {
        BlockingQueue<Runnable> queue = e.getQueue();
        int discardSize = queue.size() >> 1;
        for (int i = 0; i < discardSize; i++) {
            queue.poll();
        }
        queue.offer(r);
    }
}
 
Example 11
Source File: BlockExecutionHandler.java    From sofa-lookout with Apache License 2.0 5 votes vote down vote up
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
    if (!executor.isShutdown()) {
        try {
            executor.getQueue().put(r);
        } catch (InterruptedException e) {
            LOGGER.error("线程打断", e);
        }
    } else {
        LOGGER.error("线程池已经关闭, 丢失任务", r);
    }
}
 
Example 12
Source File: DiscardedPolicy.java    From Lottor with MIT License 5 votes vote down vote up
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
    if (threadName != null) {
        LOG.error("txTransaction Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
    }

    if (!executor.isShutdown()) {
        BlockingQueue<Runnable> queue = executor.getQueue();
        int discardSize = queue.size() >> 1;
        for (int i = 0; i < discardSize; i++) {
            queue.poll();
        }
        queue.offer(runnable);
    }
}
 
Example 13
Source File: CachedThreadPoolExecutor.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void rejectedExecution(final Runnable task, final ThreadPoolExecutor executor) {
    if (executor.isShutdown()) {
        throw new RejectedExecutionException("Executor has been shutdown.");
    }

    if (!backingQueue.offer(task)) {
        delegateRejectedExecutionHandler.rejectedExecution(task, executor);
    }
}
 
Example 14
Source File: OfferRejectedExecutionHandler.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public void rejectedExecution(final Runnable r, final ThreadPoolExecutor tpe) {

    if (null == r || null == tpe || tpe.isShutdown() || tpe.isTerminated() || tpe.isTerminating()) {
        return;
    }

    try {
        if (!tpe.getQueue().offer(r, timeout, seconds)) {
            throw new RejectedExecutionException("Timeout waiting for executor slot: waited " + timeout + " " + seconds.toString().toLowerCase());
        }
    } catch (final InterruptedException e) {
        throw new RejectedExecutionException("Interrupted waiting for executor slot");
    }
}
 
Example 15
Source File: BlockingPolicyWithReport.java    From BootNettyRpc with Apache License 2.0 5 votes vote down vote up
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
    if (threadName != null) {
        LOG.error("Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
    }

    if (!executor.isShutdown()) {
        try {
            // 添加一个元素, 如果队列满,则阻塞
            executor.getQueue().put(runnable);
        } catch (InterruptedException e) {
            // should not be interrupted
        }
    }
}
 
Example 16
Source File: FunctionExecutionPooledExecutor.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
  if (executor.isShutdown()) {
    throw new RejectedExecutionException(LocalizedStrings.PooledExecutorWithDMStats_EXECUTOR_HAS_BEEN_SHUTDOWN.toLocalizedString());
  } else {
    try {
      FunctionExecutionPooledExecutor pool = (FunctionExecutionPooledExecutor)executor;
      pool.bufferQueue.put(r);
    } catch (InterruptedException ie) {
      Thread.currentThread().interrupt();
      RejectedExecutionException e = new RejectedExecutionException(LocalizedStrings.PooledExecutorWithDMStats_INTERRUPTED.toLocalizedString());
      e.initCause(ie);
      throw e;
    }
  }
}
 
Example 17
Source File: RejectedExecutionHandlerImpl.java    From L2jOrg with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
	if (executor.isShutdown()) {
		return;
	}
	
	LOGGER.warn("{} from {} ", r, executor);
}
 
Example 18
Source File: RejectedPolicyWithReport.java    From Thunder with Apache License 2.0 5 votes vote down vote up
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
    if (threadName != null) {
        LOG.error("Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
    }

    if (runnable instanceof RejectedRunnable) {
        ((RejectedRunnable) runnable).rejected(); // 交给用户来处理
    } else {
        if (!executor.isShutdown()) {
            BlockingQueue<Runnable> queue = executor.getQueue();
            // 舍弃1/2队列元素,例如7个单位的元素,舍弃3个
            int discardSize = queue.size() >> 1;
            for (int i = 0; i < discardSize; i++) {
                // 从头部移除并返问队列头部的元素
                queue.poll();
            }

            try {
                // 添加一个元素, 如果队列满,则阻塞
                queue.put(runnable);
            } catch (InterruptedException e) {
                // should not be interrupted
            }
        }
    }
}
 
Example 19
Source File: BlockingProducersPolicyWithReport.java    From sofa-jraft with Apache License 2.0 5 votes vote down vote up
@Override
public void rejectedExecution(final Runnable r, final ThreadPoolExecutor e) {
    LOG.error("Thread pool [{}] is exhausted! {}.", threadPoolName, e.toString());

    dumpJvmInfoIfNeeded();

    if (!e.isShutdown()) {
        try {
            e.getQueue().put(r);
        } catch (InterruptedException ignored) {
            // Should not be interrupted
        }
    }
}
 
Example 20
Source File: ExecutorDispatcher.java    From vlingo-actors with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public void rejectedExecution(final Runnable runnable, final ThreadPoolExecutor executor) {
  if (!executor.isShutdown() && !executor.isTerminated())
    throw new IllegalStateException("Message cannot be sent due to current system resource limitations.");
}